Advertisement
Guest User

DataTypeFinder

a guest
Oct 8th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P1_DataTypeFinder {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scan = new Scanner(System.in);
  8.  
  9.  
  10. // FIRST SOLUTION
  11. // ========================
  12.  
  13.  
  14.  
  15. String input = "";
  16.  
  17. while (true){
  18.  
  19. input = scan.nextLine();
  20.  
  21.  
  22. if (input.equals("END")){
  23. break;
  24. }
  25.  
  26. boolean isInt = true;
  27.  
  28. try {
  29. int integer = Integer.parseInt(input);
  30.  
  31.  
  32.  
  33. } catch (NumberFormatException e) {
  34.  
  35. isInt = false;
  36.  
  37. }
  38.  
  39. boolean isFloating = true;
  40.  
  41. try {
  42.  
  43. double floatingType = Double.parseDouble(input);
  44.  
  45.  
  46. } catch (NumberFormatException e) {
  47. isFloating = false;
  48. }
  49.  
  50.  
  51. if (isInt){
  52. System.out.printf("%s is integer type%n", input);
  53.  
  54. } else if (isFloating) {
  55. System.out.printf("%s is floating point type%n", input);
  56. } else if (input.length() == 1){
  57. System.out.printf("%s is character type%n", input);
  58. } else if (input.equalsIgnoreCase("true")
  59. || input.equalsIgnoreCase("false")) {
  60.  
  61. System.out.printf("%s is boolean type%n", input);
  62.  
  63. } else {
  64.  
  65. System.out.printf("%s is string type%n",input);
  66. }
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement