Re: Simple Text Quest Help
I wrote an class not long ago to help new users get user input from the command line. You can get it here:
Valid user input.
Create a new class in eclipse called Console.java and copy all the code from the article. You do not need to change anything in this class. Now in your main method you can use it like so:
Code Java:
//Ask the user for input
String userInput = Console.readString("Enter dogs or cats: ");
//Print the result
if (userInput.equals("dogs")) {
System.out.println("Dogs it is.");
}
else if (userInput.equals("cats")) {
System.out.println("Cats it is.");
}
else {
System.out.println("Invalid input.");
}
Re: Simple Text Quest Help
Thank you very much for the help!
Re: Simple Text Quest Help
The easiest and most efficient way is to use the switch statement. Research on that and you will be fine with it soon.
Re: Simple Text Quest Help
Quote:
Originally Posted by
elisha.java
The easiest and most efficient way is to use the switch statement. Research on that and you will be fine with it soon.
If you are not aware of Java 7, how can you think switch will work for String?
Well, in Java 7, it does :P
Re: Simple Text Quest Help
Perhaps it should help to spark a programmer's curiosity! Thank you for pointing out though. You always have a point.
Re: Simple Text Quest Help
Quote:
Originally Posted by
elisha.java
Perhaps it should help to spark a programmer's curiosity! Thank you for pointing out though. You always have a point.
Everyone has the point and we all are here to help others in learning stage. I am too in a learning stage and this stage never gonna end. So, i try my best to help others to improve their concepts by simply pointing them out, as the best of my knowledge. And one more thing, i am not always correct because i am also a learner so comments are open to all to read and comment about. Hope you don't take them personal.
Re: Simple Text Quest Help
Thanks. I do not take anything personal. Learning is a lifelong process!