Computer Applications
(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?
Java Arrays
10 Likes
Answer
(a) x[3][2] = {{1, 3}, {5, 7}, {9, 11}};
(b) 14
Explanation
- x[0][1] = 3.
- x[2][1] = 11.
- Sum = 3 + 11 = 14.
Answered By
6 Likes
Related Questions
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.
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[]?
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));Define a class named CloudStorage with the following specifications:
Member Variables:
int acno – stores the user’s account number
int space – stores the amount of storage space in GB purchased by the user
double bill – stores the total price to be paid by the user
Member Methods:
void accept() – prompts the user to input their account number and storage space using Scanner class methods only.
void calculate() – calculates the bill total price based on the storage space purchased using the pricing table provided:Storage range Price per GB (Rs) First 15 GB 15 Next 15 GB 13 Above 30 GB 11 void display() – displays the account number, storage space and bill to be paid.
Write a main method to create an object of the class and invoke the methods of the class with respect to the object.