*
The moose likes Beginning Java and the fly likes Simple input commands Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple input commands" Watch "Simple input commands" New topic
Author

Simple input commands

Mark Adams
Greenhorn

Joined: Nov 23, 2007
Posts: 16
Hello, I am trying to figure out what I need to do here to get this program to accept simple char input. Please excuse the syntax as it is just a rough draft. I know I am missing another important component but can't figure out what it is. Any help is greatly appreciated.

Thanks

Mark

Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Why don't you use input.next() to return String and you can do String comparison using equals(). If you insist on using character, you can use input.next().charAt(0) to get the character and use == operator to do the comparison.

Does this help you?


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Mark Adams
Greenhorn

Joined: Nov 23, 2007
Posts: 16
Ok thanks, that seem to be so much easier. So I would just like to get anything to work here. I just cant get anything to work...
What am I doing wrong? I feell like I am starting to get so close.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
Can you explain in what way it isn't working ? Does it not compile ? Does it give the wrong output ?


Joanne
Mark Adams
Greenhorn

Joined: Nov 23, 2007
Posts: 16
This is what I am getting...

C:\Documents and Settings\tank\java>javac AgeTest.java
AgeTest.java:10: cannot find symbol
symbol : variable input
location: class AgeTest
age = input.nextInt();
^
AgeTest.java:14: cannot find symbol
symbol : variable input
location: class AgeTest
topic = input.next(",").charAt(0);
^
2 errors

C:\Documents and Settings\tank\java>
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
You haven't declared a variable called 'input'.

In your original post, you had this line
Mark Adams
Greenhorn

Joined: Nov 23, 2007
Posts: 16
Yes I did, do I need that?
Mark Adams
Greenhorn

Joined: Nov 23, 2007
Posts: 16
I am just trying to write a simple multiple choice program. Trying to figure out just how to get the results after pressing a, b, c,. b = write answer a & c = wrong answers. Looking for the best way to accomplish this. I can't find anywhere online that just simply shows how to do this. If anyone knows where I can find a simple way of doing this I would really appreciate it.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3415
    
  12
Originally posted by Mark Adams:
Yes I did, do I need that?


Yes. If you look at the error message it is complaining that the variable 'input' is not defined. That line defined it.
Add that line and I think your program should work. It will at least compile. We can then sort out any logic errors.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple input commands
 
Similar Threads
math program help..
trouble with loops and invoking a method
Break back to Topic Menu
math problems as jnlp
Can't get to next question...