Advertisement
meteor4o

Java-Fund-DataMore- 01.DataTypeFinder

May 29th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. String test = scanner.nextLine();
  9.  
  10. while (!test.equals("END")) {
  11.  
  12. try {
  13. Integer.parseInt(test);
  14. System.out.printf("%s is integer type%n", test);
  15. test = scanner.nextLine();
  16. continue;
  17. } catch (Exception ignore) {
  18. }
  19. try {
  20. Double.parseDouble(test);
  21. System.out.printf("%s is floating point type%n", test);
  22. test = scanner.nextLine();
  23. continue;
  24. } catch (Exception ignore) {
  25.  
  26. }
  27. if (test.equalsIgnoreCase("true") || test.equalsIgnoreCase("false")) {
  28. System.out.printf("%s is boolean type%n", test);
  29. } else if (test.length() == 1 && (test.charAt(0) < 48 || test.charAt(0) > 57)) {
  30. System.out.printf("%s is character type%n", test);
  31. } else {
  32. System.out.printf("%s is string type%n", test);
  33. }
  34. test = scanner.nextLine();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement