Advertisement
Guest User

Untitled

a guest
Nov 30th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _01DataTypeFinder {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = scanner.nextLine();
  8.  
  9.         while(!input.equals("END")) {
  10.             if(input.equalsIgnoreCase("true") || input.equalsIgnoreCase("false")) {
  11.                 boolean bool = Boolean.parseBoolean(input);
  12.                 System.out.printf("%s is boolean type%n", input);
  13.             } else {
  14.                 try {
  15.                     long number = Long.parseLong(input);
  16.                     System.out.printf("%s is integer type%n", input);
  17.                 } catch (Exception l) {
  18.                     try {
  19.                         double number = Double.parseDouble(input);
  20.                         System.out.printf("%s is floating point type%n", input);
  21.                     } catch (Exception f) {
  22.                         boolean isChar = input.length() == 1;
  23.                         if(isChar) {
  24.                             System.out.printf("%s is character type%n", input);
  25.                         } else {
  26.                             System.out.printf("%s is string type%n", input);
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.  
  32.             input = scanner.nextLine();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement