SJSU/Udacity CS046

Problem Set 4

  1. Gas Checker
  2. Decisions
  3. Letter Grade
  4. In Range
  5. Comes After
  6. String Equals
  7. Or
  8. Loops
  9. Powers of Two
  10. Sum Even
  11. Count Even
  12. Month
  13. Country Names
  14. Max Min Printer

Decisions

What does this code fragment print?
      int n = 1;
      int m = -1;
      if (n < -m)   
      { 
         System.out.print(n); 
      }
      else 
      {
         System.out.print(m); 
      }
-1
What does this code fragment print?
      double x = Math.sqrt(2);
      double y = 2;
      if (x * x == y)
      { 
         System.out.println("okay"); 
      }
      else 
      { 
         System.out.println("oops"); 
      }
oops
What does this code fragment print when x is 60?
      if (x > 100);
      {
         x = 100;
      }
      System.out.println(x);
100
What will this code print?
        String school = new String("Udacity");
        if (school == "Udacity")
        {
           System.out.println("equal");
        }
        else
        {
           System.out.println("not equal");
        }
not equal
Complete the if statement with the condition to determine whether the string name has a value assigned to it.
if(________________) 
name != null
Which of the following comes first in lexicographic order?
      "John"
      "john"
      "123"
"123"
Which of the following comes last in lexicographic order?
      "lesson1"
      "lesson2"
      "lesson10"
          
"lesson2"
done is a boolean variable. What is the value of !!done? done

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =