My friend Harrison sent me a Java file that was giving him trouble. He wanted to read in an Integer from in a command-line program. He found the method readInt() in the class Console. But it wouldn’t compile:
for ( i = 0; i < 5; i++)
System.out.println(“Array[“+ i +”] = “+ array[i]);
String name = null;
int age = 0;
age = Console.readInt(“Enter Age:”);
PersonTest.java:74: cannot find symbol
symbol : method readInt(java.lang.String)
location: class java.io.Console
age = console.readInt(“Int Enter Age:”);
I did a little searching and found suggestions that he was going in the right direction:
char letter = Console.readChar("Enter a letter: "); double d = Console.readDouble("Enter a real number: "); int i = Console.readInt("Enter an integer: "); String name = Console.readLine("Enter your full name: ");
hahaha! Turns out breezygui.console isn’t the same as console… the base language doesn’t actually have the readInt method, or readChar or readDouble. But apparently C# and or J++ and/or some dialect/library for C++ DO have a Console class with a readInt, readChar and readDouble members…
SO… you have to be VERY careful what the on-line document you’re counting on really says. It might have the method you want but only in a library you don’t have, or in another language completely. Ooof! is this fun or what???
Of course I showed Harrison how to get integer, double and char values he wanted. That’s what friends are for.
So be careful what you read and believe. Including this!