Write a Java program segment to find the average of the elements of an integer array a of size n.
Arrays
Original Khojo Papers practice question — not from a past board paper.
int max = a[0]; for (int i = 1; i < n; i++) if (a[i] > max) max = a[i]; System.out.println(max);
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Starting max at a[0] rather than at zero is important, because the array may contain only negative numbers.
From the same topic and chapter, at a similar level.
Write a Java program segment to find the average of the elements of an integer array a of size n.
Arrays
What happens in Java if a program accesses a[10] in an array declared as int a[] = new int[10]?
Arrays
State two differences between linear search and binary search.
Arrays
How many comparisons does binary search need in the worst case to find an element in a sorted array of 1,024 elements?
Arrays
Explain the ternary operator in Java and rewrite "if (a > b) max = a; else max = b;" using it.
Operators and Expressions in Java
What is the output of: String s = "Examination"; System.out.println(s.length() + " " + s.substring(0, 4) + " " + s.toUpperCase().charAt(2));
String Handling