NadezhdaGeorgieva

DataTypeFinder

Sep 23rd, 2020
932
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package bg.softuni.javafundamentals;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ME01DataTypeFinder {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String input = scanner.nextLine();
  9.  
  10.         while(!input.equals("END")){
  11.             Scanner sc = new Scanner(input);
  12.             if (sc.hasNextInt()){
  13.                 System.out.printf("%s is integer type%n", input);
  14.             }else if (sc.hasNextDouble()) {
  15.                 System.out.printf("%s is floating point type%n", input);
  16.             }else if (input.length() == 1) {
  17.                 System.out.printf("%s is character type%n", input);
  18.             }else if (sc.hasNextBoolean()) {
  19.                 System.out.printf("%s is boolean type%n", input);
  20.             }else if (sc.hasNextLine()) {
  21.                 System.out.printf("%s is string type%n", input);
  22.             }
  23.             input = scanner.nextLine();
  24.         }
  25.     }
  26. }
  27.  
RAW Paste Data