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 5 of 5

Thread: Issue with if logic

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    Atlanta, Georgia
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Issue with if logic

    First Thank you in Advance just for having a place for programmers to talk to each other..
    As I said in my title, I am new to java. 3rd week in class..
    I have an issue with my if statement project.. Its a long way from being done but anyway when i put in Admin it always goes to the else statement.. So I understand this is a Logic error..( Learned something )
    Here is my code if you could point a finger at where I need to focus my attention.. It would be greatly appreciated .. Thank you so much..
    import javax.swing.JOptionPane;
     
    class Name{
    	public static void main(String[] args){
    		String name = JOptionPane.showInputDialog(
                            null, "Please enter Name");
     
     
     
     
     
     
                  if(name == ("Admin")) { 
                     JOptionPane.showMessageDialog(null,  name + " welcome " );
                     }
                     else
                     { 
                          JOptionPane.showMessageDialog(null,  name + " Is not Correct! Goodbye! " );
                          } // End if
     
     
     
     
     
    	} //end main()
    } //end class


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default re: Issue with if logic

    Quote Originally Posted by dande View Post
    if(name == ("Admin")) {
    String content must be compared with equals() method ... not with == .
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

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

    dande (February 5th, 2014)

  4. #3
    Junior Member
    Join Date
    Feb 2014
    Location
    Atlanta, Georgia
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default re: Issue with if logic

    Thank you so much, I guess a little more attention paid on my part would have solved the issue. Almost every example in our book has the int data declaration so its kinda confusing.. Thank you so much for clearing that up

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default re: Issue with if logic

    Please give your threads better titles. Thanks for taking the time to learn how to post code correctly.

  6. #5
    Junior Member
    Join Date
    Feb 2014
    Location
    Atlanta, Georgia
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Issue with if logic

    Cup of Java for your kindness.. I will better title my threads :-)

Similar Threads

  1. Logic
    By KAJLogic in forum Java Theory & Questions
    Replies: 4
    Last Post: September 3rd, 2013, 04:32 PM
  2. Need logic ....!!!
    By Afzal in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 30th, 2013, 12:12 PM
  3. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  4. need logic
    By arunjib in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2011, 05:39 PM
  5. Logic issue(I believe) stumped
    By mwr76 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 23rd, 2011, 01:19 AM

Tags for this Thread