-
-
Save krystian-booker/99ae603e47853f285389521da3b5b546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class Week6Task1 { | |
public static void main(String[] args) { | |
// Declare an array of strings named colors | |
String[] colors = {"red", "blue", "green", "yellow", "purple"}; | |
// Print the third value in the array | |
System.out.println("Third color: " + colors[2]); | |
// Change the value of the second element in the array to "black" | |
colors[1] = "black"; | |
// Print the entire array to check your changes | |
System.out.println("Array after modification: " + Arrays.toString(colors)); | |
// Use a for loop to iterate over the array and print each color | |
for (int i = 0; i < colors.length; i++) { | |
System.out.println(colors[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment