Advertisement
Spocoman

01. Data Type Finder

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