Write a program to enter a number and display the addition of all numbers from 1 to the given number
Answers
Answered by
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
Math,
7 months ago
English,
7 months ago
Computer Science,
1 year ago
History,
1 year ago
Math,
1 year ago