CR7CR7

dt

Oct 12th, 2022
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DataTypeFinder {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String type = scanner.nextLine();
  8.  
  9.         while (!type.equals("END")) {
  10.             Scanner input = new Scanner(type);
  11.             if (input.hasNextBoolean()) {
  12.                 System.out.printf("%s is boolean type%n", type);
  13.             } else if (input.hasNextInt()) {
  14.                 System.out.printf("%s is integer type%n", type);
  15.             } else if (type.length() == 1) {
  16.                 System.out.printf("%s is character type%n", type);
  17.             } else if (input.hasNextDouble()) {
  18.                 System.out.printf("%s is floating point type%n", type);
  19.             } else if (input.hasNextLine()) {
  20.                 System.out.printf("%s is string type%n", type);
  21.             }
  22.             type = scanner.nextLine();
  23.         }
  24.     }
  25. }
Add Comment
Please, Sign In to add comment