Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: if statement issue

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default if statement issue

    if i enter "y" when prompted to play again, i get the "good bye" message. what is happening?

    public static void main(String args[])  
        { 
        	Scanner in = new Scanner(System.in);
        	String s;
     
        	System.out.println("Welcome\n");
        	Game newGame = new Game();
        	System.out.println();
     
        	System.out.print("Play Again? Y/N ");
        	s=in.next();
        	System.out.println();
        	if(s=="Y" || s=="y")
        	{
        		newGame = new Game();
        	}
        	else
        	{
        		System.out.print("Good Bye");
        	}
    	}


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: if statement issue

    Go here: http://www.javaprogrammingforums.com...-mistakes.html (<- link) and go down to post #9 (don't know how to leave link to direct post). Your issue has to do with the difference between == and .equals.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Elementality (February 17th, 2011)

Similar Threads

  1. Port issue?
    By Brt93yoda in forum Java Theory & Questions
    Replies: 3
    Last Post: October 13th, 2010, 04:28 PM
  2. [SOLVED] Calendar Issue
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2010, 01:19 PM
  3. i do not know how to solve this issue
    By javastupi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 20th, 2010, 08:28 PM
  4. url pattern issue - please help me...
    By bharathik in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: November 9th, 2009, 04:28 AM
  5. Issues with Tomcat 6.0
    By sanyog24681 in forum Java Servlet
    Replies: 0
    Last Post: October 21st, 2008, 07:55 AM