Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DataTypeFinder {
- 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 ignoreError){
- }
- //
- try{
- Double.parseDouble(input);
- System.out.printf("%s is floating point type%n",input);
- input = scanner.nextLine();
- continue;
- }catch (Exception ignoreError){
- }
- //
- if (input.equals("END")){
- break;
- }
- if (input.length() == 1 && (input.charAt(0) <= 47 || input.charAt(0) >= 58)){
- System.out.printf("%s is character type%n",input);
- }else if (input.equals("true") || input.equals("false")){
- System.out.printf("%s is boolean type%n",input);
- }else {
- System.out.printf("%s is string type%n",input);
- }
- input = scanner.nextLine();
- }
- }
- }
- // You will receive an input until you receive "END". Find what data type is the input. Possible data types are:
- // • Integer
- // • Floating point
- // • Characters
- // • Boolean
- // • Strings
- // Print the result in the following format: "{input} is {data type} type"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement