Advertisement
Edzhevit

Untitled

Feb 25th, 2019
2,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package DataTypesAndVariablesExercise;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Scanner;
  7.  
  8. public class DataTypeFinder {
  9. public static void main(String[] args) throws IOException {
  10. Scanner scanner = new Scanner(System.in);
  11. String input = "";
  12.  
  13. while (true){
  14. input = scanner.nextLine();
  15.  
  16. if (input.equals("END")){
  17. break;
  18. }
  19. boolean isInt = true;
  20.  
  21. try {
  22. int integer = Integer.parseInt(input);
  23. } catch (NumberFormatException e){
  24. isInt = false;
  25. }
  26.  
  27. boolean isDouble = true;
  28. try {
  29. double doubl = Double.parseDouble(input);
  30. } catch (NumberFormatException e){
  31. isDouble = false;
  32. }
  33.  
  34. if (isInt){
  35. System.out.printf("%s is integer type%n",input);
  36. } else if (isDouble){
  37. System.out.printf("%s is floating point type%n",input);
  38. } else if (input.length() == 1){
  39. System.out.printf("%s is character type%n",input);
  40. } else if (input.equalsIgnoreCase("true") || (input.equalsIgnoreCase("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. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement