write a program in which the user can enter X amount of numbers. Once the user h
ID: 669075 • Letter: W
Question
write a program in which the user can enter X amount of numbers. Once the user has enter 10 positive numbers, he or she may not enter anymore numbers. Then the program should display the sum of those 10 number and also display each of those number.In java language. Thanks in advance. write a program in which the user can enter X amount of numbers. Once the user has enter 10 positive numbers, he or she may not enter anymore numbers. Then the program should display the sum of those 10 number and also display each of those number.
In java language. Thanks in advance.
In java language. Thanks in advance.
In java language. Thanks in advance.
Explanation / Answer
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
int count=0,x;
int[] myList = new int[10];
Scanner s = new Scanner(System.in);
System.out.println("Enter the numbers in new line");
while(true){
x=s.nextInt();
if(x>0){
if (count<10){
myList[count]=x;
count++;
}
else{
break;
}
}
}
int sum=0;
for (int i = 0; i < myList.length; i++) {
System.out.println(myList[i] + " ");
sum+=myList[i];
}
System.out.println("sum is:"+sum);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.