Questions from Starting Out With Java


Q: Assume that a program has the following declarations: double number

Assume that a program has the following declarations: double number = 9.47; String str; Write a statement that assigns a string representation of the number variable to str.

See Answer

Q: The String class is immutable. What does this mean?

The String class is immutable. What does this mean?

See Answer

Q: In a program that makes lots of changes to strings, would

In a program that makes lots of changes to strings, would it be more efficient to use String objects or StringBuilder objects? Why?

See Answer

Q: Look at the following statement: String city = "Asheville

Look at the following statement: String city = "Asheville"; Rewrite this statement so that city references a StringBuilder object instead of a String object.

See Answer

Q: Complete the following program so it displays a random integer in the

Complete the following program so it displays a random integer in the range of 1 through 10. // Write the necessary import statement(s) here. public class ReviewQuestion15 { public static void main(St...

See Answer

Q: Write an if statement that displays the word “digitâ€

Write an if statement that displays the word “digit†if the char variable ch contains a numeric digit. Otherwise, it should display “Not a digit.â€.

See Answer

Q: You wish to add a string to the end of the existing

You wish to add a string to the end of the existing contents of a StringBuilder object. What method do you use?

See Answer

Q: You wish to insert a string into the existing contents of a

You wish to insert a string into the existing contents of a StringBuilder object. What method do you use?

See Answer

Q: You wish to delete a specific character from the existing contents of

You wish to delete a specific character from the existing contents of a StringBuilder object. What method do you use?

See Answer

Q: You wish to change a specific character in a StringBuilder object.

You wish to change a specific character in a StringBuilder object. What method do you use?

See Answer