Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class P1H
- {
- public static void main (String [] args)
- {
- String[] music = new String[3]; //Create an array of 3 strings
- //Populate array with name of favorite artists
- music[0] = "Kanye West";
- music[1] = "Childish Gambino";
- music[2] = "JJ Lin";
- music[(int)(Math.random()* (3))] = "Michael Jackson"; //Place Michael Jackson in a random index of array.
- for (int index = 0; index < music.length; index++) //For loop to go through music array
- {
- if (music[index].equals("Michael Jackson")) //Check if string is equal to "Michael Jackson"
- {
- System.out.println("We found Michael!"); //Print found if the condition is true
- }
- else
- {
- System.out.println("No Michael found in music" + "[" + index + "]"); //Otherwise, print not found if the condition is not true
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement