SophiYo

DataTypeFinderV.0.2

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