Questions from Starting Out With Java


Q: Find the error: int[] collection = new int[

Find the error: int[] collection = new int[−20];

See Answer

Q: int[] table = new int[10]; for (

int[] table = new int[10]; for (int x = 1; x

See Answer

Q: String[] words = { "Hello", "Goodbye" };

String[] words = { "Hello", "Goodbye" }; System.out.println(words.toUpperCase());

See Answer

Q: The following class definition has an error. What is it?

The following class definition has an error. What is it? public class MyClass { private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; } }

See Answer

Q: Find the error: int number = 99; String str

Find the error: int number = 99; String str; // Convert number to a string. str.valueOf(number);

See Answer

Q: Write a JavaFX CSS style definition that will be applied to all

Write a JavaFX CSS style definition that will be applied to all Label, Button, and TextField controls. The style definition should specify the following: font size: 24, font style: italic, font weight...

See Answer

Q: Find the error: // Change the very first character of

Find the error: // Change the very first character of a // StringBuilder object to 'Z'. str.setCharAt(1, 'Z');

See Answer

Q: Find the error: // Superclass public class Vehicle

Find the error: // Superclass public class Vehicle { (Member declarations . . .) } // Subclass public class Car expands Vehicle { (Member declarations . . .) }

See Answer

Q: Find the error: // Superclass public class Vehicle

Find the error: // Superclass public class Vehicle { private double cost; public Vehicle(double c) { cost = c; } } // Subclass public class Car extends Vehicle { private int passengers; public Car(in...

See Answer

Q: Find the error: catch (FileNotFoundException e) {

Find the error: catch (FileNotFoundException e) { System.out.println("File not found."); } try { File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); }

See Answer