Forums Register Login

is there a quicker way to read in input besides bufferedreader?

+Pie Number of slices to send: Send
i guess i could use a method or put it in a variable or something
but i'm just curious is there some other way to read input without using it at all!

also i have a question about Switch
if i want to evaluate the String or char input...what could i use
switch doesn't take these types, only ints and enum
+Pie Number of slices to send: Send
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 ...:
+Pie Number of slices to send: Send
I am on java 1.4 i think
and I figured using If/Else was the only way to look thru strings inputs
thanks for that Scanner heads up
how is that different from BufferedReader?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
The SDK I use is Eclipse. I they think they are all 1.4 versions. I may be wrong though.
+Pie Number of slices to send: Send
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).
+Pie Number of slices to send: Send
[da]: also i have a question about Switch
if i want to evaluate the String or char input...what could i use
switch doesn't take these types, only ints and enum


That's not true - a switch statement can take a char, as well as byte, short, int, or enum types.
+Pie Number of slices to send: Send
 

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.
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1304 times.
Similar Threads
method that reads a string for vowels?
IDEA ant Integration -> input hangs build
Final object's value could be changed?
do {} while statement illegal start of type
Environment variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:55:36.