Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter how many numbers you want to sum: ");
- int sumNum = sc.nextInt();
- int sum = 0;
- for (int i = 1; i <= sumNum; i++) {
- System.out.print("Enter number " + i + ": ");
- int num = sc.nextInt();
- sum += num;
- }
- System.out.println("The sum of the numbers is: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement