Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String dataType = "tbd";
- while(!input.equals("END")) {
- boolean isInt = false;
- boolean isFloat = false;
- boolean isChar = false;
- boolean isString = false;
- boolean isBool = false;
- try {
- Integer.parseInt(input);
- isInt = true;
- }
- catch(NumberFormatException e){
- isInt = false;
- }
- try {
- Double.parseDouble(input);
- isFloat = true;
- }
- catch(NumberFormatException e){
- isFloat = false;
- }
- if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("false")) {
- isBool = true;
- } else if (input.length() == 1) {
- isChar = true;
- } else if(input.length() > 1) {
- isString = true;
- }
- if (isInt) {
- System.out.printf("%s is integer type%n", input);
- } else if(isFloat) {
- System.out.printf("%s is floating point type%n", input);
- } else if(isChar) {
- System.out.printf("%s is character type%n", input);
- } else if(isString) {
- System.out.printf("%s is string type%n", input);
- } else if(isBool) {
- System.out.printf("%s is boolean type%n", input);
- }
- input = scanner.nextLine();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement