Computer Science, asked by mihikashree06, 4 months ago

write a program in java to input 10 numbers and find their sum using loops

Answers

Answered by mahithakur252007
2

The positive integers 1, 2, 3, 4 etc. are known as natural numbers. Here we will see three programs to calculate and display the sum of natural numbers.

First Program calculates the sum using while loop

Second Program calculates the sum using for loop

Third Program takes the value of n(entered by user) and calculates the sum of n natural numbers

Answered by dattarajshinde44
6

Answer:

import java.util.*;

public class Question {

public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  System.out.println("Input 10 Numbers");

  int i = 1;

  int sum = 0;

  for (i=1;i<=10;i++) {

    int a = sc.nextInt();

    sum = sum+a;

    }

 System.out.println("Sum = "+sum);

}

}

Explanation:

Using For Loop I Have Created The Above Program , First The Program Instructs The User To Input 10 Numbers & Then Using "For Loop" The Program Takes 10 Input From The User And Add The Numbers & Print The Sum..

Hope It Helps

Similar questions