Question

In: Computer Science

JAVA programing language: What is printed when the following code is executed? int columns; int rows;...

JAVA programing language:

What is printed when the following code is executed?

int columns;

int rows;

for(rows = 1; rows < 2; ++rows) {

for(columns = 1; columns < 3; ++columns) {

System.out.print("x");

}

System.out.println():

}

select one:

A)

xx

B)

xxx

xxx

C)

x

x

D)

xx

xx

xx

Solutions

Expert Solution

Answer is (A) -xx

EXPLANATION-

WHEN THE FIRST FOR LOOP EXECUTES THAT IS

//

for(row=1; row<2,++rows)

Then row will get value 1 then the control will go to the condition i.e (row<2) which is true, then the control will come to the next for loop i.e-

for(column =1; column<3;++columns)

Column is initialised with value 1 then it will check the condition (column<3) .since column is having a value 1 then (1<3) i.e the condition is true,then the control will go the next line i.e-

System.out.print("x");

So it will print -x

Then the value of column will incremented to 2, then again it will check the condition (2<3) which is true then again print -x ,

then again the value of column will be incremented to 3 and then check the condition (3<3) which evaluates to false so, the control will jump to the next line which iwill change the line to a new line and then jump to the first for loop and the value of rows will be incremented to 2 and check the condition i.e (2<2) which evaluates to false and the control will go out of that block.

So, the OUTPUT is- xx


Related Solutions

c programing language When a new program is executed, a new process is created with the...
c programing language When a new program is executed, a new process is created with the next available process ID. However, there are a few special processes that always have the same process ID, which are usually given the ID value less than 5 these are called system processes. Can you identify which of the two system processes have the process ID of 0 and 1 respectively?
JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns...
JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns to store integer values, and then: fill elements with values as the sum of its column index and row index, e.g., the element at row index 0 and column index 0 is (0+0=0), the element at row index 0 and column index 1 is (0+1=1). compute the sum of elements at the second row. compute the sum of elements at the third column. compute...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers = {22, 33, 44}; for(int k = 0; k < 3; k++) { numbers[k] = numbers[k] + 5; } } 2. What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } 3.What is the value of numbers [3] after the following line...
in java Print a list of seats in a theater. Rows are numbered, columns lettered, as...
in java Print a list of seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat. Create a nested loop to print the following: 1A 1B 1C 1D 3A 3B 3C 3D 5A 5B 5C 5D
JAVA If a user inputs a specific number of rows, columns and sections for a rectangle...
JAVA If a user inputs a specific number of rows, columns and sections for a rectangle using three symbols, how would you print using for loops and a string? Not using an array Example: If 4 was inputted for rows, 12 was inputted for columns, 6 was inputted for sections, and the following symbols (that are all chosen by the user) were “$” “*” and “%” the following would print: $$**%%$$**%% $$**%%$$**%% $$**%%$$**%% $$**%%$$**%% Has to account for all numbers...
1) What's the contents of array vals after the following code is executed? int[] vals =...
1) What's the contents of array vals after the following code is executed? int[] vals = {6, 1, 4, 5, 1}; int size = vals.length; for(int i = 0; i < size; i++) vals[i] = vals[i] * i; q) [ 6, 1, 4, 5, 1 ] b)[ 0, 1, 2, 3, 4] c)[0, 1, 8, 15, 4] d)[6, 2, 12, 20, 5] 2) Consider function foo defined below: static int[] foo(int vals[]) { int result[] = new int[vals.length - 1];...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that outputs the number in words and stores the result in the String inwords. For example, if t is 35 then inwords should contain "thirty five". Test Cases Test case #1 Expected result: When t is 2, your code sets inwords to "two" Test case #2 Expected result: When t is 50, your code sets inwords to "fifty" Test case #3 Expected result: When t...
[C++ Language] Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search...
[C++ Language] Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search and return } Selection_Sort(int a[], int z) { …..// do the selection sort } main() {     Selection_Sort(array, size);     Binary_Search(array, item); }
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
When testing for independence in a contingency table with 2 rows and 2 columns at 5%...
When testing for independence in a contingency table with 2 rows and 2 columns at 5% level of significance, the critical value of the test statistic is____
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT