About your first question: Do you mean to read input from the console window (i.e. ask the user to input a value)? If you're using Java 5 or newer, have a look at the class Scanner (in package java.util). A quick example:
Your second question: Indeed, switch does not work with chars or strings. You can use a sequence of if ... else if ...:
I think Jesper Young is correct. You would find Scanner easier to use, so I recommend you download a more recent version of Java. Remember Java 5 came out in Autumn 2004.
But is there a difference from BufferedReader? No, (if I remember correctly) Scanner is a method of encapsulating BufferedReader objects in an easy-to-use wrapper.
An alternative but more complicated way of getting different messages would be to put them as "values" into a HashMap, and use the names as "keys." Something like this:- You can put "Alice," "Brenda," and "Carol" as keys, then when the HashMap sees "Alice" it returns whichever message you put there after "Alice." Putting a message with %s in into a printf() argument list will cause printf to replace the "%s" with the name. You can also put several names with the same message.
But as I said it is a more complicated way to organise your choices, so I shall understand if you don't use it. CR
Joined: Aug 12, 2004
The SDK I use is Eclipse. I they think they are all 1.4 versions. I may be wrong though.
Joined: Oct 13, 2005
You can still download and install J6. Then in Eclipse, right-click the name of the project->properties->Java compiler->project-specific settings->compiler compliance level->6.0 (or 5). There is somewhere (I forget where) which allows you to set J6 as the default compliance.
This doesn't work if you have been told to use J1.4.2 (which I hope you haven't).
Originally posted by dawud alexander: The SDK I use is Eclipse. I they think they are all 1.4 versions. I may be wrong though.
Eclipse is not an SDK, it's an IDE (Integrated Development Environment). Eclipse doesn't come with a JDK (Java Development Kit) or JRE (Java Runtime Environment). You have to download and install a JDK or JRE yourself (which you have done, otherwise you couldn't run Eclipse, because it is itself written in Java).
Eclipse runs on Java 1.4 or newer - so if you're really using Java 1.4 you should be able to upgrade to Java 5 or 6 without any problem.
As Campbell says, you also have to set the compiler compliance level in Eclipse to the right Java version.
subject: is there a quicker way to read in input besides bufferedreader?