Advertisement
Vladkoheca

Sum of numbers.java

Oct 23rd, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         System.out.print("Enter how many numbers you want to sum: ");
  7.         int sumNum = sc.nextInt();
  8.         int sum = 0;
  9.         for (int i = 1; i <= sumNum; i++) {
  10.             System.out.print("Enter number " + i + ": ");
  11.             int num = sc.nextInt();
  12.             sum += num;
  13.         }
  14.         System.out.println("The sum of the numbers is: " + sum);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement