File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple input commands

 
Mark Adams
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mark Adams
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain in what way it isn't working ? Does it not compile ? Does it give the wrong output ?
 
Mark Adams
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't declared a variable called 'input'.

In your original post, you had this line
 
Mark Adams
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I did, do I need that?
 
Mark Adams
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic