Computing.Net > Forums > Programming > multiple character input in java

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

multiple character input in java

Reply to Message Icon

Name: valhalla
Date: November 2, 2004 at 12:22:18 Pacific
OS: win xp 64
CPU/Ram: a643200/1g
Comment:

Hey everyone. I am in real trouble.. I am new to java and realy need some help. I am writing a program with user input. I understand that (char)System.in.read(); will just give me the first character of my users respoonse, but i need to be able to read a double amount. I need it to be able to read money to the nearest penny, and i have no idea how to make java read the rest of my users response instead of only the first character. Please if someone knows a way to do this, and i know there must be a way, let me know. Thank you very much.



Sponsored Link
Ads by Google

Response Number 1
Name: wharfie
Date: November 3, 2004 at 16:23:01 Pacific
Reply:

Sounds like you want to read a string from the console not just a char.

Here's an example;

public class ReadConsole {

public static void main(String[] args) {
try {
String s = null;
String prompt = ">> ";
BufferedReader inData = new BufferedReader(new InputStreamReader(System.in));
System.out.print(prompt);
while ((s = inData.readLine()) != null && !s.toUpperCase().equals("EXIT")) {
System.out.println("You entered : " + s);
System.out.print(prompt);
}
}
catch (Exception e){
System.out.println(e);
}
System.exit(0);
}
}


0

Response Number 2
Name: valhalla
Date: November 4, 2004 at 14:52:17 Pacific
Reply:

Thank you mate!!! worked great. I cast the string to a double and there were no problems. once again thank you


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: multiple character input in java

hiding user input in java www.computing.net/answers/programming/hiding-user-input-in-java/9552.html

Huffman Coding implementation in Java www.computing.net/answers/programming/huffman-coding-implementation-in-java/19973.html

how do you compare 'char' in java www.computing.net/answers/programming/how-do-you-compare-char-in-java/4005.html