Advertisement
LittleWho

Untitled

Jan 19th, 2021
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CalssJava8 {
  4.  
  5.     public static void main(String[] args) {
  6.         // create a Scanner object
  7.         Scanner input = new Scanner(System.in);
  8.         // prompt user to enter numbers
  9.         System.out.println("Introduceti un numar");
  10.          // initialize the variables
  11.         int n,  count;
  12.         n = input.nextInt();
  13.         count = 0;
  14.         while (n != 0)
  15.         {
  16.             n = input.nextInt();
  17.         count++;
  18.         }
  19.  
  20.         System.out.println("Total numbers " + count);
  21.  
  22.     }
  23.     }
  24.  
  25. Varianta cu DO... WHILE:
  26.  
  27. package project4;
  28.  
  29. import java.util.Scanner;
  30.  
  31. public class JavaClass9 {
  32.  
  33.     public static void main(String[] args) {
  34.         // TODO Auto-generated method stub
  35.         Scanner input = new Scanner(System.in);
  36.         // prompt user to enter numbers
  37.         System.out.println("Introduceti un numar");
  38.          // initialize the variables
  39.         int n,  count;
  40.         n = input.nextInt();
  41.         count = 0;
  42.  
  43.         do {
  44.  
  45.         n = input.nextInt();
  46.         count++;
  47.  
  48.         }
  49.  
  50.         while (n != 0);
  51.         System.out.println("Total numbers " + count);
  52.     }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement