Question

In: Computer Science

Suppose x is 1 and y is 10. What is the output of the following code?...

  1. Suppose x is 1 and y is 10. What is the output of the following code?

                       

If (x> 1) && ( y <11)

                                    Display statement

                        else

                                    Display nothing

2. Suppose x is 1 and y is 10. What is the output of the following code?

                        If (x> 1) || ( y <11)

                                    Display statement

                        Else

                                    Display nothing

3. Write a java program that prints 1 to infinite numbers.

4. The following program is supposed to write out the integers 1, 2, 3, and 4. Decide what should go in the blanks.

public class Counter
{  
  public static void main (String[] args)
  {
    int count ;
    count = (blank) ;  
    while ( count (blank) 4 )  
    {
       System.out.println( count );  
        count = count + (blank)  ;  
    }
  }
}

5. The following program is supposed to write out the integers 2, 1, 0, -1 . Decide what should go in the blanks.

public class Counter3
{  
  public static void main (String[] args)
  {
    int count ;
    count = (blank) ;  
    while ( count >= (blank) )  
    {
      System.out.println( count );  
      count = count - (blank)  ;  
    }
  }
}

6. The idea of a ______________ controlled loop is that there is a special value that says when the loop is done.

Solutions

Expert Solution

1.
Suppose x is 1 and y is 10
(x> 1) && ( y <11) is False
So, It prints
Display nothing
Answer:
Display nothing

2.
Suppose x is 1 and y is 10
(x> 1) || ( y <11) is True
So, It prints
Display statement
Answer:
Display statement

3.
//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        int i = 0;
        while(true){
            System.out.println(i);
        }
    }
}

4.
public class Counter
{
  public static void main (String[] args)
  {
    int count ;
    count = 1 ;
    while ( count <= 4 )
    {
       System.out.println( count );
        count = count + 1  ;
    }
  }
}


5.
public class Counter3
{
  public static void main (String[] args)
  {
    int count ;
    count = 2 ;
    while ( count >= -1 )
    {
      System.out.println( count );
      count = count - 1  ;
    }
  }
}

6.
The idea of a sentinel controlled loop is that there is a special value that says when the loop is done.

Related Solutions

Suppose x = 0x5A and y = 0xA5. What is the output for x | y?...
Suppose x = 0x5A and y = 0xA5. What is the output for x | y? What is the output for x & y? What is x for x = ~y? What is the output for x ^ y?
What is the output of the following code: x = 0 a = 1 b =...
What is the output of the following code: x = 0 a = 1 b = -3 if a > 0:    if b < 0:       x = x + 5    elif a > 5:       x = x + 4    else:       x = x + 3 else:     x = x + 2 print(x) 4 2 5 3 Consider the following code segment:    sum = 0.0    while True:       number = input(“Enter a...
1.   What is the output of the following code: string s1 = “X”; string s2 =...
1.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s2; 2.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s[0] + s[3]; 3.   What is the output of the following code: string s1 = “X”; string...
Write the code to return the output in Rstudio. What is the code? Code: x <-...
Write the code to return the output in Rstudio. What is the code? Code: x <- c(28, 69, 5, 88, 19, 20) Output must be: [1] 4 2 1 6 5 3
1) Suppose that E(Y∣X)=X^2. Then E(Y/X) is equal to which of the following? a) 1 b)...
1) Suppose that E(Y∣X)=X^2. Then E(Y/X) is equal to which of the following? a) 1 b) E(X) c) E(X^2) d) E(Y) 2)Var(Y∣X=x) is less than or equal to Var(Y) unless Var(Y)=0. True or False?
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
(a) Suppose you are given the following x, y data pairs x 1 3 6 y...
(a) Suppose you are given the following x, y data pairs x 1 3 6 y 5 5 8 Find the least-squares equation for these data. (Use 3 decimal places.) y hat = + x (b) Now suppose you are given these x, y data pairs. x 5 5 8 y 1 3 6 Find the least-squares equation for these data. (Use 3 decimal places.) y hat = + x (c) In the data for parts (a) and (b), did...
(a) Suppose you are given the following (x, y) data pairs. x 1 3 4 y...
(a) Suppose you are given the following (x, y) data pairs. x 1 3 4 y 4 3 7 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ =  +  x (b) Now suppose you are given these (x, y) data pairs. x 4 3 7 y 1 3 4 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ =  +  x (c) In the data for parts (a) and (b), did...
(a) Suppose you are given the following (x, y) data pairs. x 1 2 5 y...
(a) Suppose you are given the following (x, y) data pairs. x 1 2 5 y 4 3 6 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ = + x (b) Now suppose you are given these (x, y) data pairs. x 4 3 6 y 1 2 5 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ = + x (c) In the data for parts...
10. Suppose that X, Y and Z are normally distributed where X ≈ N(100,100), Y ≈...
10. Suppose that X, Y and Z are normally distributed where X ≈ N(100,100), Y ≈ N(400, 400) and Z ≈ N(64,64). Let W = X + Y + Z. a) Describe the distribution of W, give a name and parameters E(W) and Var(W). b) Use Excel or R to generate 200 random values for X, Y and Z. Add these to obtain 200 values for W. Create a histogram for W. In Excel use the NORMINV(rand(),mean, sd) function. c)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT