SophiYo

DataTypeFinder

Jan 31st, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package O2DataTypesAndVar.MoreExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex01DataTypeFinder {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         while (!scanner.hasNext("END") ) {
  9.  
  10.                 System.out.println(
  11.                         scanner.hasNextInt() ? scanner.nextInt() + " is integer type" :
  12.                                 scanner.hasNextFloat() ? scanner.nextFloat() + " is floating point type" :
  13.                                         scanner.hasNextBoolean() ? scanner.nextBoolean() + " is boolean type" :
  14.                                                  scanner.hasNextLine() && scanner.toString().length() != 1 ? scanner.next() + " is string type" :
  15.                                                        scanner.toString() + " is character type"
  16.                 );
  17.         }
  18.  
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment