Computer Science, asked by shifin5990, 1 year ago

Write a program to enter a number and display the addition of all numbers from 1 to the given number

Answers

Answered by Punya2138
0

import java.io.*;

class Num

{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int n, sum=0;

public void accept()throws IOException

{System.out.println("Enter a number");

n=Integer.parseInt(br.readLine());

}

public void calc()

{ for(int d=1;d<=n;d++)

{ sum=sum+d;

}

System.out.println(" The sum of numbers ="+sum);

}

}

Similar questions