Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DataTypeFinder {
  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.  
  11. try{
  12. Integer.parseInt(input);
  13. System.out.printf("%s is integer type%n",input);
  14.  
  15. input = scanner.nextLine();
  16. continue;
  17.  
  18. }catch (Exception ignoreError){
  19.  
  20. }
  21.  
  22. //
  23. try{
  24. Double.parseDouble(input);
  25. System.out.printf("%s is floating point type%n",input);
  26.  
  27. input = scanner.nextLine();
  28. continue;
  29.  
  30. }catch (Exception ignoreError){
  31.  
  32. }
  33. //
  34. if (input.equals("END")){
  35. break;
  36. }
  37.  
  38. if (input.length() == 1 && (input.charAt(0) <= 47 || input.charAt(0) >= 58)){
  39. System.out.printf("%s is character type%n",input);
  40. }else if (input.equals("true") || input.equals("false")){
  41. System.out.printf("%s is boolean type%n",input);
  42. }else {
  43. System.out.printf("%s is string type%n",input);
  44. }
  45.  
  46.  
  47. input = scanner.nextLine();
  48.  
  49.  
  50. }
  51.  
  52.  
  53. }
  54.  
  55. }
  56. // You will receive an input until you receive "END". Find what data type is the input. Possible data types are:
  57. // • Integer
  58. // • Floating point
  59. // • Characters
  60. // • Boolean
  61. // • Strings
  62. // Print the result in the following format: "{input} is {data type} type"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement