Advertisement
Guest User

Data Types Issue

a guest
Nov 30th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | Software | 0 0
  1. package _02DataTypesAndVariables_Bonus;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _01DataTypeFinder {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String input = scanner.nextLine();
  10.  
  11. while(!input.equals("END")) {
  12. if(input.equals("true") || input.equals("false")) {
  13. boolean bool = Boolean.parseBoolean(input);
  14. System.out.printf("%b is boolean type%n", bool);
  15. } else {
  16. try {
  17. long number = Long.parseLong(input);
  18. System.out.printf("%d is integer type%n", number);
  19. } catch (Exception l) {
  20. try {
  21. double number = Double.parseDouble(input);
  22. System.out.printf("%.1f is floating point type%n", number);
  23. } catch (Exception f) {
  24. boolean isChar = input.length() == 1;
  25. if(isChar) {
  26. System.out.printf("%c is character type%n", input.charAt(0));
  27. } else {
  28. System.out.printf("%s is string type%n", input);
  29. }
  30. }
  31. }
  32. }
  33.  
  34. input = scanner.nextLine();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement