Rajat B.
asked 12/09/22
write a program in java using while loop of accept 5 numbers from the user and print the addition
Nathan P.
answered 12/17/22
Experienced Java Tutor & Software Engineer | Berkeley Grad
Scanner reader = new Scanner(System.in);
int sum = 0;
int count = 1;
while (count <= 5) {
System.out.printf("Enter number %d: ", count);
int n = reader.nextInt();
sum = sum + n;
count = count + 1;
}
reader.close();
System.out.println(sum);
Still looking for help? Get the right answer, fast.
OR
Find an Online Tutor Now
Choose an expert and meet online.
No packages or subscriptions, pay only for the time you need.