Convert the following nested for loop into a nested while loop:
for(i = 1 ; i <= rows; i++)
{
for (j = 1 ; j <= rows; j++)
{
if (bombCells[i][j])
{
System.out.print(" * ");
}
else
{
System.out.print(" . ");
}
}
System.out.println();
}
i = 1; while (i <= rows) { j = 1; while(j <= rows) { if (bombCells[i][j]) { System.out.print(" * "); } else { System.out.print(" . "); } j++; } System.out.println(); i++; }
Convert the following nested for loop into a nested while loop: for(i = 1 ; i...
convert nested for loop into nested while loop please: int[][] sol = new int[rows + 2][columns + 2]; for (i = 1 ; i <= rows ; i++) { for (j = 1 ; j <= columns ; j++) { // (ii, jj) indexes neighboring cells for (int ii = i - 1 ; ii <= i + 1 ; ii++) { for (int jj = j - 1 ; jj <=...
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...
QUESTION 8 What is the exact output of the following nested loop? for (int row = 2; row<10; row += 4){ int column=1; while (column <= 4){ System.out.print(row - column + ""); column += 2; System.out.println(); wo- 1-153 1-1 53 All of these are correct.
[Textbook Chapter 5 Self-Check Problems: Question 2] Convert each of the following for loops into an equivalent while loop: for (int n = 1; n <= max; n++){ System.out.println(n): int total = 25: for (int number - 1; number <= (total/2): number++){ total total number: System.out.println(total +""+ number): for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 3; j++){ for (int k = 1; k<= 4; k++) { System.out.print("*"); System.out.print("!"); System.out.println(); int...
1) Convert the "Switch" statement to "if/else" 2) Convert from for loop to while loop Convert the following "switch" statement to an equivalent "if/else": switch(x) case 10: cost- 1; break; case 20: cost- 2; break; default: cost 0; 0 if (cost =-1) x = 1; else if (cost-20) x = 2; else x = 0; O if ( x = 10) cost = 1; else if (x = 2) cost-20; else cost = 0; if (case10) cost 1; else if...
Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...
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;
What does the following nested loop structure output? count = 1; while (count <= 11) {innerCount = 1 while (innerCount <= (12 - count)/2) {cout << " "; innerCount++;} innerCount = 1; while (innerCount = 1; while (innerCount <= count) {cout << "0"; innerCount++;} cout << endl; count++;} What does the following nested loop structure output? count = 1; while (count <= 10) {innerCount = 1; while (innerCount <= 10) {cout << setw(5) << count * innerCount; innerCount++;} cout <<...
11) 16 pts. Convert the following for loop to a while loop. (You may want to do the following question first.) int mine [5] = {10, 11, 12); for (int j=1; j < 5; j++) cout <<j<< "" << mine[jl <<" " << end1; 12) 6 pts. What is the output of the previous question? 13) 4 pts. Circle the variables that would NOT cause syntax errors 2-smaTT , entry# break -my-int
using C++ 1. Convert the following while loop into a for loop: int count = 0; while (count < 10) x = count + sin(x); y = count + cos(y); count++;