Java : Problem - 04

Problem: -

  1. Write a program to compare two strings.

Solution: -

1. Write a program to compare two strings.

import java.util.*;

class login {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String id = "msm1012";
String pass = "msm@1012";

System.out.print("Enter username: ");
String usrId = scan.nextLine();
System.out.print("Enter password: ");
String usrPass = scan.nextLine();

if (id.equals(usrId)) {
if (pass.equals(usrPass)) {
System.out.println("\nLogin Successful...");
} else {
System.out.println("\nIncorrect Password...");
}
} else {
System.out.println("\nIncorrect Username & Password...");
}

}
}

Output: -

Mj Mausam

Post a Comment

Previous Post Next Post