SJSU/Udacity CS046

Problem Set 3

  1. Numbers
  2. Volume of a Cone
  3. Last Digit
  4. Average
  5. String Length
  6. Concatenation
  7. Strings
  8. If Statements
  9. First Character
  10. Last Character
  11. Yard Calculator
  12. Mileage Printer
  13. Balloon

If Statements

Write an if statement to test if an int variable age is equal to 21. if (age == 21)
Look at following if statement to compute a discounted price:
if (originalPrice > 100)
{
   discountedPrice = originalPrice - 20;
}
else
{
   discountedPrice = originalPrice - 10;
}
What is the discounted price when the original price is 95? 100? 105?
85, 90, 85
Given the following String definition, use the substring method to write the code to assign the word "city" to the String variable tail. Do not use a String literal in the assignment. (No fair coding tail = "city".)
String s = "Udacity";
String tail = s.substring(3, 7); You can also use String tail = s.substring(3);
What does the following code segment print?
      String s = "2";
      String t = s + s;
      System.out.print(t);
22

Problem on this page?

Your name:

Your email address:

Problem description:

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