I want to add an if statement to the following while loop. The two variables that would go in the brackets of the if statement are integers, so there's a conflict between boolean and integer values. I am an absolute beginner so I have no experience with OOP. I know basic if, else, else-if, and just learnt while loops today. So for this:
boolean boolpin == entry, boolpin2 = (pin == 12345);
I searched online to find how to convert integer to boolean which I hoped would allow me to run the if statement.
Here is the code:
import java.util.Scanner;
public class EnterPIN {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
int pin, entry;
String words;
pin = 12345;
System.out.print(" Welcome to the Bank of JAVA. " );
System.out.print("Enter your pin: " );
entry = keyboard.nextInt();
boolean boolpin == entry, boolpin2 = (pin == 12345);
if ( boolpin == boolpin2 ) {
System.out.println("\nPIN ACCEPTED: YOUR BALANCE IS 69,420.666" );
}
else {
while ( entry != pin ) {
System.out.println("\nINCORRECT PIN. TRY AGAIN.");
System.out.print("NTER YOUR PIN: ");
entry = keyboard.nextInt();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire