Write a JAVA program that has a for loop that loops ten times. Each time the loop occurs enter a number, if -6 is entered end the loop. Find the sum of the numbers entered. Use a for loop.
import java.util.Scanner; public class ForSum { public static void main(String[] args) { Scanner in = new Scanner(System.in); int sum = 0, num; for (int i = 0; i < 10; i++) { System.out.print("Enter a number(-6 to exit): "); num = in.nextInt(); if (num == -6) break; sum += num; } System.out.println("Sum of entered numbers is " + sum); } }
Get Answers For Free
Most questions answered within 1 hours.