Computer Applications
Write a program using while loop to generate the first 10 natural numbers and their sum.
Java
Java Iterative Stmts
87 Likes
Answer
public class KboatNaturalNumbers
{
public static void main(String args[]) {
int n = 1;
int sum = 0;
while (n <= 10) {
System.out.println(n);
sum = sum + n;
n = n + 1;
}
System.out.println("Sum = " + sum);
}
}
Output
Answered By
37 Likes
Related Questions
Write a program in Java using for loop to print all the odd and even number upto 30 terms.
Program to check whether the product of two numbers is a buzz number or not.
[A number that ends with 7 or is divisible by 7, is called a buzz number]Write a program to print all the factors of 20.
Generate the following series upto 10 terms:
1, 8, 27, 64, 125 ……..