write a main module that includes a loop that will loop 5 times. With each iteration, ask the user for a number, and accumulate the sum. After the loop, print the sum of the numbers.
/*********** Sum5.java ************
import java.util.Scanner;
public class Sum5 {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int sum = 0, n;
for (int i = 0; i < 5; i++)
{
System.out.println("Enter a number: ");
n =
sc.nextInt();
sum = sum +
n;
}
System.out.println("Sum = " +
sum);
}
}
Get Answers For Free
Most questions answered within 1 hours.