Computer Applications
Give the output of the following program segment:
int n[] ={1,2,3,5,7,9,13,16};
double a=Math.pow(n[4], n[1]);
double b=Math.sqrt(n[5]+n[7]);
System.out.println("a=" + a);
System.out.println("b=" + b);
Java
Java Arrays
32 Likes
Answer
a=49.0
b=5.0
Working
n[4] is 7 and n[1] is 2. Math.pow(n[4], n[1]) becomes Math.pow(7, 2) so a becomes 49.0. Next, n[5] is 9 and n[7] is 16. Math.sqrt(n[5]+n[7]) becomes Math.sqrt(9 + 16) ⇒ Math.sqrt(25) ⇒ 5.0
Answered By
15 Likes
Related Questions
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033
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