Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class P1H
  2. {
  3. public static void main (String [] args)
  4. {
  5. String[] music = new String[3]; //Create an array of 3 strings
  6.  
  7. //Populate array with name of favorite artists
  8. music[0] = "Kanye West";
  9. music[1] = "Childish Gambino";
  10. music[2] = "JJ Lin";
  11.  
  12. music[(int)(Math.random()* (3))] = "Michael Jackson"; //Place Michael Jackson in a random index of array.
  13.  
  14. for (int index = 0; index < music.length; index++) //For loop to go through music array
  15. {
  16. if (music[index].equals("Michael Jackson")) //Check if string is equal to "Michael Jackson"
  17. {
  18. System.out.println("We found Michael!"); //Print found if the condition is true
  19. }
  20. else
  21. {
  22. System.out.println("No Michael found in music" + "[" + index + "]"); //Otherwise, print not found if the condition is not true
  23. }
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement