Results 1 to 2 of 2
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Not print if statement

    where im doing mistake in this code if statement is not printing but else printing

    Java Code:
    import java.util.*;
    public  class Cyber 
    {
    	public static void main(String[] args)
    	{
    	System.out.println("Enter User Name : ");
    Scanner in=new Scanner(System.in);
    String us=in.next();
    String us1="vknehra10";
    
    
    if(us==us1)
    {
      System.out.println("Enter Password : ");
    }
    else
    {
    	System.out.println("terminate");
    }
    	}
    }
    Last edited by vknehra10; 12-13-2016 at 11:46 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Not print if statement

    Don't use == to compare Strings.
    Use the equals() method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 3
    Last Post: 11-26-2012, 11:06 AM
  2. cant access a print statement from a different class!
    By javabeginner29 in forum New To Java
    Replies: 1
    Last Post: 02-17-2012, 12:23 PM
  3. Multiple colors in print-statement
    By schutter07 in forum New To Java
    Replies: 8
    Last Post: 11-20-2010, 11:46 AM
  4. How to format the print statement
    By ftrengnr in forum New To Java
    Replies: 1
    Last Post: 09-18-2010, 10:02 PM
  5. problems with print statement
    By soccer_kid_6 in forum New To Java
    Replies: 8
    Last Post: 03-22-2010, 02:24 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •