Computer Science, asked by qwerty01, 11 months ago

Java program to print n natural numbers and their sum

please help me tomorrow is my exam

Answers

Answered by bidisha496
3
\huge\bf\red{\mid{\overline{\underline{Question :}}}\mid}

Java program to print n natural numbers and their sum.



\huge\bf\red{\mid{\overline{\underline{Program : }}}\mid}

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
amannishad0512p5zxh6: Mein sabse jadda woh padta hu
amannishad0512p5zxh6: mere parents toh school mein complain bhi karte hai
amannishad0512p5zxh6: You have to learn to answer the programming
amannishad0512p5zxh6: using commenting so that a person would understood better
amannishad0512p5zxh6: okk
bidisha496: okay...
amannishad0512p5zxh6: Aur meri reuqest accept ki
amannishad0512p5zxh6: request on brainly
bidisha496: okay...
Similar questions