In: Computer Science
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 20;
while( x > 10 ) {
System.out.println( x );
x--;
}
}
Consider the code below. What needs to be placed instead of ??? so that loop is run exactly 7 times?
public static void main(String args[]) {
int x = 7;
while( x > ??? ) {
System.out.println( x );
x--;
}
}
Consider the code below. How many times the value of x is printed?
(In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 10;
while( x < 20 ) {
System.out.println( x );
x++;
}
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 1;
while( x < 20 ) {
System.out.println( x );
x++;
}
}
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 13;
while( x > 1 ) {
System.out.println( x );
x--;
}
}
Consider the code below. How many times loop is executed?
public static void main(String args[]) {
int x = 0;
while( x <= 10 ) {
System.out.println( x );
x= x+2;
}
}
Consider the code below. How many times loop is executed?
public static void main(String args[]) {
int x = 10;
while( x <= 20 ) {
System.out.println( x );
x= x+3;
}
}
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 15;
while( x > 7 ) {
System.out.println( x );
x--;
}
}
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 20;
while( x > 10 ) {
System.out.println( x );
x--;
}
}
Solutions :9 times loop will execute.
Consider the code below. What needs to be placed instead of ??? so that loop is run exactly 7 times?
public static void main(String args[]) {
int x = 7;
while( x > ??? ) {
System.out.println( x );
x--;
}
}
Solution : 8 is replaced with ???
Consider the code below. How many times the value of x is printed?
(In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 10;
while( x < 20 ) {
System.out.println( x );
x++;
}
Solution: 0 times
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 13;
while( x > 1 ) {
System.out.println( x );
x--;
}
}
Solution :12 times
Consider the code below. How many times loop is executed?
public static void main(String args[]) {
int x = 0;
while( x <= 10 ) {
System.out.println( x );
x= x+2;
}
}
Solution: 5 times
Consider the code below. How many times loop is executed?
public static void main(String args[]) {
int x = 10;
while( x <= 20 ) {
System.out.println( x );
x= x+3;
}
}
Solution: 3times
Consider the code below. How many times the value of x is printed? (In other words, how many times the loop is executed?)
public static void main(String args[]) {
int x = 15;
while( x > 7 ) {
System.out.println( x );
x--;
}
}
Solution : 8times