Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pr1DataTypeFinder {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- while (!input.equals("END")) {
- try {
- Integer.parseInt(input);
- System.out.printf("%s is integer type%n", input);
- input = scanner.nextLine();
- continue;
- } catch (Exception ignored) {
- }
- try {
- Float.parseFloat(input);
- System.out.printf("%s is floating point type%n", input);
- input = scanner.nextLine();
- continue;
- } catch (Exception ignored) {
- }
- try {
- if (input.length() > 1 && !input.toLowerCase().equals("true") && !input.toLowerCase().equals("false")) {
- System.out.printf("%s is string type%n", input);
- input = scanner.nextLine();
- continue;
- }
- } catch (Exception ignored) {
- }
- try {
- if (input.length() == 1) {
- input.charAt(0);
- System.out.printf("%s is character type%n", input);
- input = scanner.nextLine();
- continue;
- }
- } catch (Exception ignored) {
- }
- try {
- if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false")) {
- System.out.printf("%s is boolean type%n", input);
- input = scanner.nextLine();
- }
- } catch (Exception ignored) {
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment