Hello,
I tried to catch it, but it not work.
Finally, I don't know, this has influence to fail the last point.
package pl.codegym.task.task15.task1519;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
/*
Różne metody dla różnych typów
*/
public class Solution {
public static void main(String[] args) throws IOException {
//tutaj wpisz swój kod
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String keyInput;
do {
keyInput = reader.readLine();
int countDot = 0;
boolean isNum = false;
boolean isAlpha = false;
for (char c : keyInput.toCharArray()) {
if (c == '.') {
countDot++;
}
if (Character.isDigit(c)) {
isNum = true;
}
if (!Character.isDigit(c)) {
isAlpha = true;
}
}
if (isNum == true) {
// req. 3.
if (countDot == 1 && isNum == true) {
print(Double.parseDouble(keyInput));
}
else if (countDot > 1 && isNum == true) {
print(keyInput);
}
// req. 4.
else if (isNum == true && Integer.parseInt(keyInput) > 0 && Integer.parseInt(keyInput) < 128) {
print(Short.parseShort(keyInput));
}
//req. 5.
else print(Integer.parseInt(keyInput));
}
// where input is with letters and numbers example "q1"
else if (isNum == true && isAlpha == true) { // here I try to fix a problem with input "q1" value, but it didn't work.
print(keyInput);
}
else print(keyInput);
} while (!keyInput.equals("exit"));
}
public static void print(Double value) {
System.out.println("To jest Double. Value: " + value);
}
public static void print(String value) {
System.out.println("To jest String. Value: " + value);
}
public static void print(short value) {
System.out.println("To jest liczba całkowita typu short. Value: " + value);
}
public static void print(Integer value) {
System.out.println("To jest liczba całkowita typu Integer. Value: " + value);
}
}