Computer Applications
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};
(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?
Java Arrays
ICSE Sp 2025
6 Likes
Answer
(a) The position of 34 is x[2][0]
(b) x[2][3] + x[1][2] = 9 + 8 = 17
Explanation:
(a) Position of 34
- The array
x
is a 2D array, where elements are accessed using row and column indices. - The element
34
is located in the 3rd row and 1st column. - In zero-based indexing:
- Row index:
2
- Column index:
0
Position: x[2][0]
(b) Result of x[2][3] + x[1][2]
Step 1: Locate x[2][3]
x[2][3]
refers to the element in the 3rd row and 4th column.- Value at
x[2][3]
=9
.
Step 2: Locate x[1][2]
x[1][2]
refers to the element in the 2nd row and 3rd column.- Value at
x[1][2]
=8
.
Step 3: Add the Values
x[2][3] + x[1][2]
=9 + 8
=17
.
Answered By
3 Likes
Related Questions
A student is trying to convert the string present in x to a numerical value, so that he can find the square root of the converted value. However the code has an error. Name the error (syntax / logical / runtime). Correct the code so that it compiles and runs correctly.
String x= "25"; int y=Double.parseDouble(x); double r=Math.sqrt(y); System.out.println(r);
Consider the following program segment and answer the questions below:
class calculate { int a; double b; calculate() { a=0; b=0.0; } calculate(int x, double y) { a=x; b=y; } void sum() { System.out.println(a*b); }}
Name the type of constructors used in the above program segment?
Define a class with the following specifications:
Class name: Bank
Member variables:
double p — stores the principal amount
double n — stores the time period in years
double r — stores the rate of interest
double a — stores the amountMember methods:
void accept () — input values for p and n using Scanner class methods only.
void calculate () — calculate the amount based on the following conditions:Time in (Years) Rate % Upto 1⁄2 9 > 1⁄2 to 1 year 10 > 1 to 3 years 11 > 3 years 12 void display () — display the details in the given format.
Principal Time Rate Amount XXX XXX XXX XXX
Write the main method to create an object and call the above methods.
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.