Computer Applications
Give the output of the following program segment:
int x[] = {4, 3, 7, 8, 9, 10};
int p = x.length;
int q = x[2] + x[5] * x[1];
System.out.println("p=" + p);
System.out.println("q=" + q);
Java
Java Arrays
23 Likes
Answer
p=6
q=37
Working
- x.length gives the number of elements in the array which in this case is 6
- x[2] + x[5] * x[1] ⇒ 7 + 10 * 3 ⇒ 7 + 30 ⇒ 37
Answered By
8 Likes
Related Questions
Define a class to accept values into 4x4 array and find and display the sum of each row.
Example:
A[][]={{1,2,3,4},{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Output:
sum of row 1 = 10 (1+2+3+4) sum of row 2 = 26 (5+6+7+8) sum of row 3 = 16 (1+3+5+7) sum of row 4 = 11 (2+5+3+1)Write a Java program to store n numbers in an one dimensional array. Pass this array to a function number(int a[]). Display only those numbers whose sum of digit is prime.
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100