Advertisement
Guest User

Untitled

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