Questions from Starting Out With Java


Q: Find the error: try { number = Integer

Find the error: try { number = Integer.parseInt(str); } catch (Exception e) { System.out.println(e.getMessage()); } catch (IllegalArgumentException e) { System.out.println("Bad number format."); } cat...

See Answer

Q: Find the error: // This code has an error!

Find the error: // This code has an error! @Override public void start(Scene primaryScene) { primaryScene.show(); }

See Answer

Q: Assume hbox is an HBox container: // This code has

Assume hbox is an HBox container: // This code has an error! hbox.setAlignment(CENTER);

See Answer

Q: Find the error: // This code has an error!

Find the error: // This code has an error! myImageView.setWidth(100); myImageView.setHeight(100);

See Answer

Q: Find the error: .button { -fx-background

Find the error: .button { -fx-background-color = #0000FF; }

See Answer

Q: Find the error: // This code has an error!

Find the error: // This code has an error! RadioButton radio1 = new RadioButton("Option 1"); RadioButton radio2 = new RadioButton("Option 2"); ToggleGroup radioGroup = new ToggleGroup(); radioGroup.se...

See Answer

Q: What will the following code output? int apples = 0

What will the following code output? int apples = 0, bananas = 2, pears = 10; apples += 10; bananas *= 10; pears /= 10; System.out.println(apples + " " + bananas + " " + pears);

See Answer

Q: Write functional RGB notation for a color where red=100,

Write functional RGB notation for a color where red=100, green=20, and blue= 255.

See Answer

Q: Find the error in the following program: public class FindTheError

Find the error in the following program: public class FindTheError { public static void main(String[] args) { myMethod(0); } public static void myMethod(int num) { System.out.print(num + " "); myMetho...

See Answer

Q: The following statement is in a class that uses Swing components:

The following statement is in a class that uses Swing components: import java.swing.*;

See Answer