24.6k views
2 votes
PLEASE HELP
THIS IS A BEGINNER’S COMP SCI CLASS AND THE LANGUAGE IS JAVA!

PLEASE HELP THIS IS A BEGINNER’S COMP SCI CLASS AND THE LANGUAGE IS JAVA!-example-1

1 Answer

3 votes

Answer:

is this you looking for?

import java.util.Scanner;

public class PIN {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int pin = 1234;

int userPIN = 0;

int attempts = 0;

while (userPIN != pin && attempts < 3) {

System.out.print("Enter your PIN: ");

userPIN = input.nextInt();

if (userPIN != pin) {

System.out.println("Invalid PIN, try again");

attempts++;

}

}

if (attempts == 3) {

System.out.println("Attempt limit exceeded. Account has been locked");

} else {

System.out.println("Access granted");

}

}

}

User Leo Lerdorf
by
4.5k points