Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P1_DataTypeFinder {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- // FIRST SOLUTION
- // ========================
- String input = "";
- while (true){
- input = scan.nextLine();
- if (input.equals("END")){
- break;
- }
- boolean isInt = true;
- try {
- int integer = Integer.parseInt(input);
- } catch (NumberFormatException e) {
- isInt = false;
- }
- boolean isFloating = true;
- try {
- double floatingType = Double.parseDouble(input);
- } catch (NumberFormatException e) {
- isFloating = false;
- }
- if (isInt){
- System.out.printf("%s is integer type%n", input);
- } else if (isFloating) {
- System.out.printf("%s is floating point type%n", input);
- } else if (input.length() == 1){
- System.out.printf("%s is character type%n", input);
- } else if (input.equalsIgnoreCase("true")
- || input.equalsIgnoreCase("false")) {
- System.out.printf("%s is boolean type%n", input);
- } else {
- System.out.printf("%s is string type%n",input);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement