Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. /**
  2. * Help! I used too many lines of code. Help me make this more efficient.
  3. * This main method must create an array with the same four words. Then I
  4. * have to test each word using the password method. I have to print a
  5. * message that the password was accepted.
  6. * @param args
  7. */
  8. public static void main(String[] args) {
  9. int count = 0;
  10. String[] words = {"Imagine", "yourself", "on", "Mars"};
  11.  
  12. for(int x = 0; x < words.length; x++){
  13. boolean answer = password(words[x]);
  14. if (answer == true){
  15. System.out.println("Password accepted");
  16. }
  17. else{
  18. //No action is required if the password fails.
  19. }
  20. }
  21. }
  22.  
  23. public static boolean password(String w){
  24. boolean answer = w.equals("Mars");
  25. if(answer == true) return true;
  26. return false;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement