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")) {
- String dataType = "";
- if (input.equalsIgnoreCase("true")
- || (input.equalsIgnoreCase("false"))) {
- dataType = "boolean";
- } else if (input.length() == 1) {
- char symbol = input.charAt(0);
- if (symbol < 47 || symbol > 58) {
- dataType = "character";
- } else {
- dataType = "integer";
- }
- } else {
- boolean isString = false;
- boolean isFloat = false;
- for (int i = 0; i < input.length(); i++) {
- char currentSymbol = input.charAt(i);
- if (currentSymbol < 45 || currentSymbol > 57) {
- isString = true;
- }
- if (currentSymbol == 46) {
- isFloat = true;
- }
- }
- if (isString) {
- dataType = "string";
- } else {
- if (isFloat) {
- dataType = "floating point";
- } else {
- dataType = "integer";
- }
- }
- }
- System.out.printf("%s is %s type%n", input, dataType);
- input = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment