I have problem. I get this exercise but idk how i can resolve this last three solution in my code. I need print FAIL but i cant get because i only get OK OK i thats all.
I need to compare two passwords, one is String password and the other is String checkPassword. The program is to compare each letter or number separately, if it is the same it should print OK, so if it compares the password 123 to 123 it should write OK OK PASS, if 123 to 124 then OK OK FAIL, if 123 to 12 then OK OK FAIL, if 123 to 1234 is OK OK OK FAIL, and if 123 to 81234 it should throw FAIL.
package NewPackage;
/*
password = 123
checkPassword(123) -> OK OK PASS
checkPassword(124) -> OK OK FAIL
checkPassword(12) -> OK OK FAIL
checkPassword(1234) -> OK OK OK FAIL
checkPassword(81234) -> FAIL
*/
public class Tworzenie_tablicy_char {
public static void main(String[] args) {
String password = "123";
String checkPassword = "12";
char[] charPassword = new char[password.length()];
char[] charCheckPassword = new char[checkPassword.length()];
for (int i = 0; i < password.length(); i++) {
charPassword[i] = password.charAt(i);
//System.out.println(password.charAt(i));
}
for (int i = 0; i < checkPassword.length(); i++) {
charCheckPassword[i] = checkPassword.charAt(i);
//System.out.println(checkPassword.charAt(i));
}
int minLength = Math.min(charPassword.length, charCheckPassword.length);
for (int i = 0; i < minLength; i++) {
boolean correctly = charPassword[i] == charCheckPassword[i];
if (correctly == true) {
System.out.println("OK");
} else {
System.out.println("FAIL");
}
}
}
}
Any suggestions ??