Results 1 to 6 of 6
Thread: String question
- 05-12-2010, 07:55 AM #1
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
String question
Hi, im new to using java and i was just wondering how get the user to enter a direction. So far i have:
but i dont know what to put next so that the user can input it.String direction;
System.out.print("What direction would you like the ant to move? (U, UR, R...) ");
i want it to be similar to this
but with a String.System.out.print("Enter your ant's y-coordinate: ");
y = keyboard.nextInt();
thanks
- 05-12-2010, 07:59 AM #2
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
you'll need a scanner for console input. =) something like...
that'll grab the next string inputted by the user. then you've got to check it to make sure they inputted the data you need, of course.Java Code:Scanner scanner = new Scanner(System.in); String direction; System.out.print("What direction would you like the ant to move? (U, UR, R...) ") direction = scanner.next();
- 05-12-2010, 08:04 AM #3
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
thankyouthankyouthankyouthankyou :)
- 05-12-2010, 08:05 AM #4
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
no problem. =) have fun.
- 05-12-2010, 08:48 AM #5
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
ok, now when i try to get it to do something when U is inserted its not working.
I tried this.
but it doesnt change the value of y :(System.out.print("What direction would you like the ant to move? (U, UR, R...) ");
direction = scanner.next();
if(direction.equals("U"))
{
y =+ 1;
}
- 05-12-2010, 08:53 AM #6
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
JOptionPane String to int question
By blackstormattack in forum New To JavaReplies: 3Last Post: 03-08-2009, 12:14 AM -
String to Expression? calculator app question
By Belbis in forum New To JavaReplies: 2Last Post: 12-24-2008, 07:13 AM -
question on string tokenizer
By munigantipraveen in forum New To JavaReplies: 2Last Post: 05-23-2008, 05:00 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks