Question

In: Computer Science

Consider the code below. How many times the value of x is printed? (In other words,...

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--;

      }

   }

Solutions

Expert Solution

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


Related Solutions

Based on the source code below, add codes to count how many times array has been...
Based on the source code below, add codes to count how many times array has been access by this program in sorting the array using the insertion sort. Explain how did you count the number of array access on this code. Note that this program tests on 100 until 5000 integers, with increment of 100. import random #create randomized array of length 'length' from range 0 up to max def create_array(length=100, max=5000): return [random.randint(0,max) for _ in range(length)] #executes insertion...
How many times should the following C code print "Example" and draw a process graph #include...
How many times should the following C code print "Example" and draw a process graph #include <stdio.h> #include <sys/types.h> #include <unistd.h> void try() { fork(); printf("Example\n"); fork(); return; } int main() { try(); fork(); printf("Example\n"); exit(0); }
translation: Genetic code; codon. How many codons are there? How many code for amino acids? What...
translation: Genetic code; codon. How many codons are there? How many code for amino acids? What do the others do? What is the genetic code? tRNA; anticodon; aminoacyl-tRNA synthetase. What key role do aminoacyl-tRNA synthetases play in translation? Why is there more than one? Ribosome structure. What are ribosomes made of? Where are they made? Why are there 3 tRNA binding sites? Translation initiation complex Why wouldn't a transcribed mRNA not be translated immediately? Elongation & translocation in translation. In...
Consider the DataSource class in below code. Explain how inheritance is intended to be used with...
Consider the DataSource class in below code. Explain how inheritance is intended to be used with this class. Does this represent a good use of inheritance? Explain your answer // Base class for game configuration public abstract class DataSource {     private Graph map;     private HashMap <String,Room> rooms;     private ArrayList <Entity> entities;     private Player player;     protected HashMap < String, List<String[]> > tables;     // constructor     public DataSource() {     }     // Connect to the...
What are the acquisition costs for questions 1 and 2 below? In other words, how much...
What are the acquisition costs for questions 1 and 2 below? In other words, how much out of pocket will you pay to pay for the laptop? 1. It’s time to get a new laptop. The laptop is $2500. You decide to put money aside for it each month for one year. If you put the money in an account that earns 5%, how much will you have to save each month? 2. Instead of saving up, you decide to...
2. How many seven – letter code words can be formed using a standard 26 letter...
2. How many seven – letter code words can be formed using a standard 26 letter alphabet (12 points) a.         if repetition is allowed? b.         if repetition is not allowed? c.         if the first letter has to be a C and the rest of the letters are different? d.         if the first two letters have to be a vowel and the rest of the letters are different?
QUESTION 1 Consider the Boolean function F(x, y) = x + y, how many cells in...
QUESTION 1 Consider the Boolean function F(x, y) = x + y, how many cells in the Kmap representing this function have value of “1”? A. 3 B. 2 C. 4 D. 1 10 points    QUESTION 2 Using Kmap for simplification, we can select multiple smaller groups (instead of a larger group) as long as all “1” are selected. A. False B. True 10 points    QUESTION 3 In Kmap representation, how many values of “0” and “1” two...
Many times, innovative idea comes from other industries or other fields of work, please provide one...
Many times, innovative idea comes from other industries or other fields of work, please provide one example of such innovation. Read more about this from HBR's Sometimes the Best Ideas Come from Outside Your Industry (M. Poetz, N. Franke, and M. Schreier).
How many times would integration by parts needs to be performed to evaluate ∫75xn ln(x) dx  (where...
How many times would integration by parts needs to be performed to evaluate ∫75xn ln(x) dx  (where n is a positive integer)? Multi Choice.    A- Integration by parts need to be performed 1 time in order to evaluate ∫75xn ln(x) dx.    B- Integration by parts need to be performed n − 1 times in order to evaluate ∫75xn ln(x) dx.    C- Integration by parts need to be performed n + 1 times in order to evaluate ∫ 75xn...
How many times of “3” are expected to get in rolling an unloaded dice 50 times?...
How many times of “3” are expected to get in rolling an unloaded dice 50 times? Select one: a. 25 times b. 8 times c. 16.67 times d. 8.33 times
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT