Results 1 to 5 of 5
- 04-05-2010, 10:50 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Help with my traffic light program
When I type in 'green' at the prompt 'Enter your traffic light colour:', 'GO' is not output. Can anyone help.
Java Code:package testing; import java.util.Scanner; public class trafficlight { public static void main(String[] args) { Scanner Scanner1 = new Scanner (System.in); System.out.println("Enter your traffic light colour:"); String userinput = Scanner1.nextLine(); //Testing the user input from the Scanner if (userinput == "green"){ System.out.println("GO");} else if (userinput == "amber"){ System.out.print("GET READY");} else if (userinput == "red"){ System.out.print("STOP");} } }Last edited by Eranga; 04-09-2010 at 02:55 PM. Reason: added code tags
- 04-05-2010, 11:03 PM #2
Member
- Join Date
- Apr 2010
- Posts
- 15
- Rep Power
- 0
You need to use this code instead of the one you have...
Java Code:if (userinput.equals("green")){ System.out.println("GO");}
- 04-09-2010, 02:41 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Thank you for your help
Thanks for your help with that code askinne2, it works perfectlly.
- 04-09-2010, 02:44 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 15
- Rep Power
- 0
No problem sir. Goodluck with the rest of your semester.
- 04-09-2010, 02:56 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
Generate IP/Ethernet traffic
By vincent2001@gmail.com in forum New To JavaReplies: 0Last Post: 08-22-2008, 10:08 PM -
Traffic simulator
By dirtycash in forum New To JavaReplies: 1Last Post: 03-12-2008, 03:59 AM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
Heavy and light component mixing
By Bojevnik in forum AWT / SwingReplies: 2Last Post: 08-13-2007, 11:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks