Commit d7901b64 authored by Qazi Zain's avatar Qazi Zain

new task are added

parent d043845c
package JavaTrainingTask.Question4a;
import java.util.Scanner;
public class Password {
int pin;
Scanner obj;
Password()
{
System.out.println("Object is created!");
pin = 0;
obj = new Scanner(System.in);
}
void checkPassword() {
boolean value = true;
int count = 0;
final int correctPassword = 1234;
while (value && count < 3)
{
System.out.println("Enter the password:");
pin = obj.nextInt();
if (pin == correctPassword)
{
System.out.println("Access granted!");
value = false;
}
else
{
count++;
System.out.println("Incorrect password. Try again.");
if (count == 3) {
System.out.println("Maximum attempts reached. Access denied.");
}
}
}
}}
\ No newline at end of file
package JavaTrainingTask.Question4a;
public class main {
public static void main(String[] args) {
Password obj = new Password();
obj.checkPassword();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment