0

I have tried it the way shown below but when i enter username as OMBHAYDE it prints welcome mr ombhayde along with sorry and when i type username as VIJAYBHAYDE it says welcome mr om bhayde instead vijay bhayde. Pls help.

String name1 = "OMBHAYDE";
    int key1 = 15062003;
    String name2 = "VIJAYBHAYDE";
    int key2 = 17081967;


        Scanner sc = new Scanner(System.in);
        System.out.println("Username-");
        String username = sc.nextLine();
        System.out.println("Password-");
        int password = sc.nextInt();
    if (username == name1 && password == key1 );
    System.out.println("Welcome Mr.Om Bhayde");
    if (username == name2 && password == key2)
    System.out.println("Welcome Mr.Vijay Bhayde");
    else
        System.out.println("Sorry");
OM BHAYDE
  • 1
  • 1
  • It will always print "Welcome Mr.Om Bhayde" because the first `if ()` ends with a semicolon, which means that the print statement is executed unconditionally. – Thomas Kläger Jul 18 '21 at 10:49
  • Thank you Mr.Thomas. I have solved this issue. Actually i have just started with java so i am learning – OM BHAYDE Jul 19 '21 at 04:02

0 Answers0