aspose file tools*
The moose likes Beginning Java and the fly likes is there a quicker way to read in input besides bufferedreader? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is there a quicker way to read in input besides bufferedreader?" Watch "is there a quicker way to read in input besides bufferedreader?" New topic
Author

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

Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
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
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

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 ...:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
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?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
The SDK I use is Eclipse. I they think they are all 1.4 versions. I may be wrong though.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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).
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[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.


"I'm not back." - Bill Harding, Twister
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: is there a quicker way to read in input besides bufferedreader?