mirozspace

Untitled

Feb 3rd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr1DataTypeFinder {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.  
  8.         while (!input.equals("END")) {
  9.             try {
  10.                 Integer.parseInt(input);
  11.                 System.out.printf("%s is integer type%n", input);
  12.                 input = scanner.nextLine();
  13.                 continue;
  14.             } catch (Exception ignored) {
  15.             }
  16.  
  17.             try {
  18.                 Float.parseFloat(input);
  19.                 System.out.printf("%s is floating point type%n", input);
  20.                 input = scanner.nextLine();
  21.                 continue;
  22.             } catch (Exception ignored) {
  23.             }
  24.             try {
  25.                 if (input.length() > 1 && !input.toLowerCase().equals("true") && !input.toLowerCase().equals("false")) {
  26.                     System.out.printf("%s is string type%n", input);
  27.                     input = scanner.nextLine();
  28.                     continue;
  29.                 }
  30.             } catch (Exception ignored) {
  31.             }
  32.  
  33.             try {
  34.                 if (input.length() == 1) {
  35.                     input.charAt(0);
  36.                     System.out.printf("%s is character type%n", input);
  37.                     input = scanner.nextLine();
  38.                     continue;
  39.                 }
  40.             } catch (Exception ignored) {
  41.             }
  42.  
  43.             try {
  44.                 if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false")) {
  45.                     System.out.printf("%s is boolean type%n", input);
  46.                     input = scanner.nextLine();
  47.                 }
  48.             } catch (Exception ignored) {
  49.             }
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment