Java program to print n natural numbers and their sum
please help me tomorrow is my exam
Answers
Answered by
3
Java program to print n natural numbers and their sum.
import java.io.*;
class natural_numbers
{
public static void main(Stringargs[])throws IOException
{
InputStreamReader x =new InputStreamReader (System.in);
BufferedReader y =new BufferedReader(x);
int n, i,
System.out.print("Enter the number of terms:" );
n= Integer.parseInt(y.readLine);
for(i=1; i<=n; i ++)
{
System.out.print("Natural numbers ="+n+", ");
s= s + i;
}
System.out.print("Sum of natural numbers ="+s);
}
}
I hope it helps you...
amannishad0512p5zxh6:
I toooo love java
Similar questions