Advertisement
NadezhdaGeorgieva

DataTypeFinder

Sep 23rd, 2020
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement