Advertisement
paganoantonio

Untitled

Mar 19th, 2022
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3.         Scanner scan = new Scanner(System.in);
  4.  
  5.         System.out.println("Inserisci un numero : ");
  6.         int input = scan.nextInt();
  7.  
  8.         if (input != 0) {
  9.             System.out.println("Numero di input : " + input);
  10.             System.out.print("I primi n numeri naturali sono: ");
  11.             int somma = 0;
  12.             for (int x = input; x > 0; x--) {
  13.                 System.out.print(x + ",");
  14.                 somma = somma + x;
  15.             }
  16.             System.out.println(" ");
  17.             System.out.print("la somma del numero naturale fino a n termini รจ : " + somma);
  18.  
  19.         }
  20.  
  21.     }
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement