Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CalssJava8 {
- public static void main(String[] args) {
- // create a Scanner object
- Scanner input = new Scanner(System.in);
- // prompt user to enter numbers
- System.out.println("Introduceti un numar");
- // initialize the variables
- int n, count;
- n = input.nextInt();
- count = 0;
- while (n != 0)
- {
- n = input.nextInt();
- count++;
- }
- System.out.println("Total numbers " + count);
- }
- }
- Varianta cu DO... WHILE:
- package project4;
- import java.util.Scanner;
- public class JavaClass9 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner input = new Scanner(System.in);
- // prompt user to enter numbers
- System.out.println("Introduceti un numar");
- // initialize the variables
- int n, count;
- n = input.nextInt();
- count = 0;
- do {
- n = input.nextInt();
- count++;
- }
- while (n != 0);
- System.out.println("Total numbers " + count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement