Questions from Starting Out With Java


Q: Write a loop that asks the user, “Do you

Write a loop that asks the user, “Do you want to repeat the program or quit? (R/Q)”. The loop should repeat until the user has entered an R or Q.

See Answer

Q: What will the following code display? char var = '

What will the following code display? char var = '$'; System.out.println(Character.toUpperCase(var));

See Answer

Q: Write a loop that counts the number of uppercase characters that appear

Write a loop that counts the number of uppercase characters that appear in the String object str.

See Answer

Q: Write a method that accepts a reference to a String object as

Write a method that accepts a reference to a String object as an argument and returns true if the argument ends with the substring “gerâ€. Otherwise, the method should return false.

See Answer

Q: Modify the method so it performs a case-insensitive test.

Modify the method so it performs a case-insensitive test. The method should return true if the argument ends with “ger†in any possible combination of uppercase and lowercase letters.

See Answer

Q: Look at the following declaration: String cafeName = "Broadway

Look at the following declaration: String cafeName = "Broadway Cafe"; String str; Which of the following methods would you use to make str reference the string “Broadwayâ€. startsWith regionMatches...

See Answer

Q: Write a for loop that displays the following set of numbers:

Write a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000

See Answer

Q: Here is the first line of a class declaration. What is

Here is the first line of a class declaration. What is the name of the superclass? What is the name of the subclass? public class Truck extends Vehicle

See Answer

Q: How do you prevent a method from being overridden?

How do you prevent a method from being overridden?

See Answer

Q: When a class member is declared as protected, what code may

When a class member is declared as protected, what code may access it?

See Answer