A_Marinov

Untitled

Sep 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package MoreExcercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DataType_01 {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         String input = scan.nextLine();
  10.  
  11.         while (!"END".equals(input)) {
  12.             Scanner readData = new Scanner(input);
  13.  
  14.             checkDataType(readData, input);
  15.  
  16.             input = scan.nextLine();
  17.         }
  18.     }
  19.  
  20.     private static void checkDataType(Scanner readData, String input) {
  21.         if (readData.hasNextInt()) {
  22.             System.out.printf("%s is integer type%n", input);
  23.         } else if (readData.hasNextDouble()) {
  24.             System.out.printf("%s is floating point type%n", input);
  25.         } else if (input.length() == 1) {
  26.             System.out.printf("%s is character type%n", input);
  27.         } else if (readData.hasNextBoolean()) {
  28.             System.out.printf("%s is boolean type%n", input);
  29.         } else if (readData.hasNextLine()) {
  30.             System.out.printf("%s is string type%n", input);
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment