Advertisement
Yuvalxp8

Count following numbers

Jan 28th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ex17 {
  4.     public static void main(String []args)
  5.     {
  6.         Scanner in = new Scanner(System.in);
  7.         int num = 0;
  8.         int counter = 0;
  9.         while(num != -1)
  10.         {
  11.             System.out.println("Enter number between 0-9 and enter -1 to finish");
  12.             int newnum = in.nextInt();
  13.             if(num == newnum-1)
  14.             {
  15.                 counter++;
  16.             }
  17.             num = newnum;
  18.         }
  19.         System.out.println(counter);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement