QUESTIONS WITH CORRECT SOLUTIONS!!
Write a method that loops until the user inputs the correct secret password or until the user
fails to enter the correct password 10 times. The secret password the program should look for
is the String "secret"
public void secretPassword()
{
A.
int count = 1
while(true)
{
if(count == 10)
{
Systemoutprintln("You are locked out!")
return
}
String readLine = input.nextLine()
if(readLine.equals("secret"))
{
Systemoutprintln("Welcome!")
return
}
count++
}
}
B.
int count = 0
while(true)
{
if(count == 10)
{
Systemoutprintln("You are locked out!")
}
String readLine = input.nextLine()
if(readLine.equals("secret"))
{
System.out.println("Welcome!")
}
count++
}
}
C.
int count = 0
while(true)
, {
if(count == 10)
{
System.out.println("You are locked out!")
return
}
String readLine = input.nextLine()
if(readLine.equals("secret"))
{
System.out.println("Welcome!")
return
}
count++
}
} correct answers C.
public void secretPassword()
{
int count = 0;
while(true)
{
if(count == 10)
{
System.out.println("You are locked out!");
return;
}
String readLine = input.nextLine();
if(readLine.equals("secret"))
{
System.out.println("Welcome!");
return;
}
count++;
}
}
What would the method call myMethod("Karel The Dog", 'e') return?
public int myMethod(String x, char y)
{
int z = 1;
for(int i = 0; i < x.length(); i++)
{
if(x.charAt(i) == y)
{
z++;
}
}
return z;
}