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 |