program to generate first ten natural number and their sum
Answers
Answered by
2
public class Sum
{
public static int a()
{
int c = 1, sum;
while(c < = 10)
{
sum = sum + c;
c++;
}
System.out.println(sum);
}
}
• Flow Of Program
1. Class created
2. Method declared
3. Two variables declared and one initialized
4. Loop started
5. Variable 'sum' is updated with values till the condition is satisfied
6. The control variable is incremented
7. Loop closed
8. Result printed
9. Method closed
10. Class closed
{
public static int a()
{
int c = 1, sum;
while(c < = 10)
{
sum = sum + c;
c++;
}
System.out.println(sum);
}
}
• Flow Of Program
1. Class created
2. Method declared
3. Two variables declared and one initialized
4. Loop started
5. Variable 'sum' is updated with values till the condition is satisfied
6. The control variable is incremented
7. Loop closed
8. Result printed
9. Method closed
10. Class closed
Similar questions