Array Initializers
public class Main {
public static void main(String[] args) {
int[] odds = { 1, 3, 5, 7, 9 };
System.out.println("odds.length = " + odds.length);
for (int i = 0; i < odds.length; i++) {
System.out.println("odds[" + i + "] = " + odds[i]);
}
String[] daysOfWeek = { "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday" };
System.out.println("\ndaysOfWeek.length = " + daysOfWeek.length);
for (int i = 0; i < daysOfWeek.length; i++) {
System.out.println("daysOfWeek[" + i + "] = " + daysOfWeek[i]);
}
}
}
Related examples in the same category