Unit 6 ยท Arrays and strings
Java arrays have fixed length and zero-based indexes from 0 through length - 1. A traversal should use the array's length rather than a hard-coded endpoint.
int[] marks = {72, 81, 64, 90};
int total = 0;
int highest = marks[0];
for (int mark : marks) {
total += mark;
if (mark > highest) highest = mark;
}
System.out.println(total / (double) marks.length);String objects are immutable. Methods such as trim, toUpperCase, and substring return new strings. Compare content with equals or equalsIgnoreCase.
name.toUpperCase() not change name?Mastery task: Create a survey analyzer that stores ratings, reports a distribution, and finds the most common rating.