Miguel_Angel
Miembro habitual
Me da la sensación que algo he hecho mal aunque el programa funciona.
// Write a Java program that stores user passwords in an array.
// The passwords are shown below.
// oxymoran
// poxedfox
// kingfisher
// cruiseshipper
// Create a variable to store the name of a user’s password.
// Assign it the value, cruiseshipper.
// Using an enhanced for loop, search the array for the password.
// If the password is found, display the message, “Log-On Successful”.
// Use the break keyword to leave the looping construct early, if so.
// After searching the array, if the password is not found,
// display a single error message to the user.
// “You cannot be logged on using the specified password.”
class JFT8Ex10
{
public static void main (String args[])
{
String Passwords [] = {"oxymoran", "poxedfox", "kingfisher", "cruiseshipper"};
String userPassword = "cruiseshipper";
for (String passwords : Passwords)
{
if (userPassword == "cruiseshipper")
{
System.out.println ("Log - On Successful");
break;
}
else
{
System.out.println ("You cannot be logged on using the specified password");
break;
} //End of Else statement
} // End of FOR statement
} // End of main method
} // End of class
// Write a Java program that stores user passwords in an array.
// The passwords are shown below.
// oxymoran
// poxedfox
// kingfisher
// cruiseshipper
// Create a variable to store the name of a user’s password.
// Assign it the value, cruiseshipper.
// Using an enhanced for loop, search the array for the password.
// If the password is found, display the message, “Log-On Successful”.
// Use the break keyword to leave the looping construct early, if so.
// After searching the array, if the password is not found,
// display a single error message to the user.
// “You cannot be logged on using the specified password.”
class JFT8Ex10
{
public static void main (String args[])
{
String Passwords [] = {"oxymoran", "poxedfox", "kingfisher", "cruiseshipper"};
String userPassword = "cruiseshipper";
for (String passwords : Passwords)
{
if (userPassword == "cruiseshipper")
{
System.out.println ("Log - On Successful");
break;
}
else
{
System.out.println ("You cannot be logged on using the specified password");
break;
} //End of Else statement
} // End of FOR statement
} // End of main method
} // End of class