Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DataTypeFinder2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input;
- String dataType = "undefined";
- while( !(input = sc.nextLine()).equals("END") ) {
- Scanner scanner = new Scanner(input);
- if(scanner.hasNext()) {
- if(scanner.hasNextInt()){
- int token = scanner.nextInt();
- dataType = "integer";
- }else if(scanner.hasNextDouble()){
- double token = scanner.nextDouble();
- dataType = "floating point";
- }else if(scanner.hasNextBoolean()){
- boolean token = scanner.nextBoolean();
- dataType = "boolean";
- }else{
- String token = scanner.next();
- if(token.length() == 1){
- dataType = "character";
- }else{
- dataType = "string";
- }
- }
- }
- scanner.close();
- System.out.printf("%s is %s type%n", input, dataType);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement