Computer Applications
Write Java statements for the following:
(a) Initialise the array with the three favourite subjects.
(b) Declare an array to store the marks in 3 subjects of 40 students.
Java Arrays
1 Like
Answer
(a) String subjects[] = {"Maths", "Science", "English"};
(b) int marks[][] = new int[40][3]; or int marks[][] = new int[3][40];
Answered By
1 Like
Related Questions
Convert the following for loop segment to an exit-controlled loop.
for(k = 10;k >= -1;k--) System.out.println(k*2); System.out.println(k*4);Give the output of the following program segment:
int x[]={2,45,7,67,12,3}; int i, t=0; for(i=0, t=5;i<3;i++,t--) { System.out.println(x[i]+x[t]); }A Student executes the given program segment and it results in 1.0, irrespective of the value of n. State the type of the error, write the correct statement:
void solve(int n) { double power=Math.pow(n, 2/3); System.out.println(power); }Consider the following program segment and answer the questions given:
for(int k=1;k<=5;k++) System.out.println(k); System.out.println(k);(a) Will the program segment get executed successfully?
(b) If not, state the type of error?
(c) How do you correct the program if it has any error?