Advertisement
lol1234561

Untitled

Mar 28th, 2023
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner keyboard = new Scanner(System.in);
  5.         System.out.println("Please choose a number: ");
  6.         int num = keyboard.nextInt();
  7. int total = 0;
  8.         for (int n = 1; n <= num; n = n+1){
  9.  
  10.             System.out.println(n + " ");
  11.  total = total + n;
  12.  
  13.  
  14.         }
  15.         System.out.println("The sum is: "+ total);
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement