Computer Applications
Consider the following array and answer the questions given below:
int a[] = {12, 10, 8, 4, 6, 2, 3, 5, 7};
(a) What is the output of System.out.print(a[0] + a[5]);?
(b) What is the index (subscript) of the largest element of the array a[]?
Java Arrays
6 Likes
Answer
(a) 14
(b) The largest element in the array is 12, which is at index 0.
Explanation
- a[0] is 12.
- a[5] is 2.
- Sum = 12 + 2 = 14.
Answered By
3 Likes
Related Questions
(a) Name one String method which results in positive integer only.
(b) Name one String method which results in a character.
John was asked to write a Java code to calculate the surface area of a cone. The following code was written by him: Surface area of cone is A = πrl
l =
class area{ double area(double r, double h){ double l, a; a = 22.0 / 7 * r * l; l = Math.sqrt(r * r + h * h); return a; } }Specify the type of the error in the above program, correct and write the program to be error free.
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.
(b) What is the result of x[0][1] + x[2][1] of the above array?
Give the output of the following program segment and specify how many times the loop is executed.
String s = "JAVA"; for(i = 0; i < s.length(); i += 2) System.out.println(s.substring(i));