Skip to content

Instantly share code, notes, and snippets.

@krystian-booker
Created August 3, 2023 00:43
Show Gist options
  • Save krystian-booker/99ae603e47853f285389521da3b5b546 to your computer and use it in GitHub Desktop.
Save krystian-booker/99ae603e47853f285389521da3b5b546 to your computer and use it in GitHub Desktop.
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