Solution:
Given code
for(int row=2;row<10;row+=4){
int column=1;
while(column<=4){
System.out.print(row-column+"");
column+=2;
}
System.out.println();
}
out of all the 4 given options for the above code the 3rd option is correct that is
1 -1
5 3
Because
Initally row=2 and row<10 it is true then column=1 and column <=4 it is also true so it prints row-column as 2-1=1.
column increment by 2 so column value=3 and it is less than 4 so again it prints row-column as 2-3=-1
then column value incremented by 2 and becomes 5 so the condition in while loop is not true so it terminates.
System.out.println()nprints a new line. again the row value incremented by 4
row=2+4=6 and row<10 it is true then column=1 and column <=4 it is also true so it prints row-column as 6-1=5.
column increment by 2 so column value=3 and it is less than 4 so again it prints row-column as 6-3=3
then column value incremented by 2 and becomes 5 so the condition in while loop is not true so it terminates.
System.out.println()nprints a new line. again the row value incremented by 4
row=6+4=10 and the condition row<10 becomes false loop terminated.
so finally the exact output is
1 -1
5 3
Tested output image is attached below
QUESTION 8 What is the exact output of the following nested loop? for (int row =...
What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;
QUESTION 8 What (if anything) will be the output of the following code: int count = 3; while (count++ <= 6) { System.out.print(++count + " "); } 3 4 5 6 4 5 6 7 3 4 5 6 7 5 7 4 6 The above code contains a syntax error and will not run. 8 points QUESTION 9 What (if anything) will be the output of the following code: int count = 0; while (count < 5) {...
Thie What is the output of the following program segment? int count 1; do System.out.print(count (count-) + while(count++ <= 5);
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...
how and why is this the answer as well? thank you 35. What is the output of the following code? for (int j = 0; j < 7; ;=j+2) { for (int k = j; k < 4; k++) System.out.print("hey"); { System.out.println(".");
What is the output of the following? int sum=3, z=1; do { printf("The sum:%d*", sum+z); } while (sum<= 1); printf("0"); * 1 (2 Points) 40 4
Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;
Please answer both questions thank you. Question 52 (1 point) What is the output of the code snippet given below? String s = "abcde"; int i = 1; while (i < 5) { System.out.print(s.substring(i, i + 1)); i++; Question 50 (1 point) How many times will the output line be printed in the following code snippet? Please enter your answer as an integer. for (int i = 0; i < 3; i++) { for (int j = 1; j <...
C++ 5.How many times will the following loop run? int i=5; while (i19) 6 . What is the output of the following code snippet? int time 1; int year2 int rate = 1; int principal = 5; int interest-0 cout <<i < endl while (year< 5) interest (principal * time rate) /1 ; cout << interest << endl; year++