Собственно, если запустить программу и попробовать ввести в консоль все эти типы данных,
то программа все распознает, но почему же компиляция не проходит.Может компилятор не совсем различает Boolean и String?
package com.javarush.task.task06.task0610;
/*
Класс ConsoleReader
*/
import java.io.*;
public class ConsoleReader {
public static String readString(String stringInput) throws Exception {
String result = stringInput;
return result;
}
public static int readInt(int intInput) throws Exception {
int result = intInput; //= Integer.parseInt(input);
return result;
}
public static double readDouble(double doubleInput) throws Exception {
double result = doubleInput;// Double.parseDouble(input);
return result;
}
public static boolean readBoolean(boolean booleanInput) throws Exception {
boolean result = booleanInput;// Boolean.parseBoolean(input);
return result;
}
public static void main(String[] args) throws Exception {
InputStream is = System.in;
Reader isR = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isR);
String input = reader.readLine();
try {
int intInput = Integer.parseInt(input);
int result = ConsoleReader.readInt(intInput);
System.out.println(result);
} catch (NumberFormatException e2) {
System.out.println(e2.getMessage() + "Sorry, I'll try double parsing and get result");
try {
double doubleInput = Double.parseDouble(input);
double result = ConsoleReader.readDouble(doubleInput);
System.out.println(result);
} catch (NumberFormatException e3) {
System.out.println(e3.getMessage() + "Sorry, I'll try boolean parsing and get result");
boolean booleanInput = Boolean.parseBoolean(input);
boolean result = ConsoleReader.readBoolean(booleanInput);
System.out.println(result);
try {
int intInput = Integer.parseInt(input);
int result1 = ConsoleReader.readInt(intInput);
System.out.println(result1);
} catch (NumberFormatException e) {
System.out.println(e.getMessage() + "Sorry, I'll try String parsing and get result");
String stringInput = input;
String result1 = ConsoleReader.readString(stringInput);
System.out.println(result1);
}
}
}
}
}