public class ConsoleReader {
public static String readString() throws Exception {
Scanner sc1 = new Scanner(System.in);
String s = sc1.nextLine();
return s;
}
public static int readInt() throws Exception {
Scanner sc1 = new Scanner(System.in);
int s = sc1.nextInt();
return s;
}
public static double readDouble() throws Exception {
Scanner sc1 = new Scanner(System.in);
double s = sc1.nextInt();
return s;
}
public static boolean readBoolean() throws Exception {
Scanner sc1 = new Scanner(System.in);
boolean bl = Boolean.parseBoolean(sc1.nextLine);
return bl;
}
public static void main(String[] args) {
}
}
Any hints here?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
horst
12 January 2020, 19:26
Two remarks:
1. Scanner has a ".nextBoolean()" method, so I think you don't have to parse anything here. (If it works, however, just let it be as it is)
2. Just closely re-read your code again, there is a very obvious flaw in it that you will surely spot yourself. (You carefully made sure that the String method reads a String, the Int method reads an Int, but...?)
0