Write a program that takes two words as input from the keyboard, representing a
ID: 3654177 • Letter: W
Question
Write a program that takes two words as input from the keyboard, representing a user ID and a password. Your program should do the following: -If the user ID and the password match "admin and "open" receptively, then output "Welcome." -If the user Id matches "admin but the passwornd is wrong then output "wrong passord" -if the password matches but the user id is wrong then output "Wrong user ID" -otherwise output "Sorry wrong ID and password" here is what I have I am just messing up the syntax //page 277 #52 import java.util.Scanner; public class Login { public static void main(String[] args) { String userID, Password; Scanner user = new Scanner(System.in); System.out.print("Enter the user Id "); userID = user.nextLine(); Scanner pass = new Scanner(System.in); System.out.print("Enter the Password "); Password = pass.nextLine(); if (userID.indexOf("admin") >= 0) ++(Password.indexOf("open") >= 0); System.out.println("Welcome"); else if System.out.println(userID ); } }Explanation / Answer
package oct29; import java.util.Scanner; public class Login { public static void main(String[] args) { String userID, Password; Scanner user = new Scanner(System.in); System.out.print("Enter the user Id "); userID = user.nextLine(); Scanner pass = new Scanner(System.in); System.out.print("Enter the Password "); Password = pass.nextLine(); if (userID.equalsIgnoreCase("admin") && Password.equalsIgnoreCase("open")) System.out.println("Welcome"); else if (userID.equalsIgnoreCase("admin")) System.out.println("Wrong password"); else if(Password.equalsIgnoreCase("open")) System.out.println("Wrong UserId"); else System.out.println("Wrong password and userId"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.