how to work with letters in java code example
Example 1: java manipulate alphabet list
String usernameInDatabase = "modernNerd";String passwordInDatabase = "mN123Java";String providedUsername = "modernnerd";String providedPassword = "mN123Java";if(providedUsername.equalsIgnoreCase(usernameInDatabase)){ //successful username comparison //check the provided password //this will fail //if("mn123java".equals(passwordInDatabase)){} //this will pass if(providedPassword.equals(passwordInDatabase)){ System.out.println("Success! You are logged in."); } else { System.out.println("Wrong password. Try again."); }} else { //user provided wrong username System.out.println("Wrong username. Try again.");}
Example 2: java manipulate alphabet list
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";int indexOfLetterD = alphabet.indexOf("D");//indexOfLetterD equals 3