Reges Marty Stepp (Solutions Manual All Chapters, 100%
Original Verified, A+ Grade) All Chapters Solutions Manual
Supplement files download link at the end of this file.
Building Java Programs, 3rd Edition
Exercise Solutions
NOTE: Answers to exercises are considered a private resource for instructors. Please do not post these
answers on a public web site. Other instructors assign these problems as homework and do not want
the answers to become publicly available. Thank you.
Many exercises can be solved in more than one way. Some exercises have more than one solution
shown.
Chapter 1
1. public class Stewie {
public static void main(String[] args) {
System.out.println("//////////////////////");
System.out.println("|| Victory is mine! ||");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
}
}
2. public class Spikey {
public static void main(String[] args) {
System.out.println(" \\/");
System.out.println(" \\\\//");
System.out.println("\\\\\\///");
System.out.println("///\\\\\\");
System.out.println(" //\\\\");
System.out.println(" /\\");
}
}
,3. public class WellFormed {
public static void main(String[] args) {
System.out.println("A well-formed Java program has");
System.out.println("a main method with { and }");
System.out.println("braces.");
System.out.println();
System.out.println("A System.out.println statement");
System.out.println("has ( and ) and usually a");
System.out.println("String that starts and ends");
System.out.println("with a \" character.");
System.out.println("(But we type \\\" instead!)");
}
}
4. public class Difference {
public static void main(String[] args) {
System.out.println("What is the difference between");
System.out.println("a ' and a \"? Or between a \" and a \\\"?");
System.out.println();
System.out.println("One is what we see when we're typing our program.");
System.out.println("The other is what appears on the \"console.\"");
}
}
5. public class MuchBetter {
public static void main(String[] args) {
System.out.println("A \"quoted\" String is");
System.out.println("'much' better if you learn");
System.out.println("the rules of \"escape sequences.\"");
System.out.println("Also, \"\" represents an empty String.");
System.out.println("Don't forget: use \\\" instead of \" !");
System.out.println("'' is not the same as \"");
}
}
,6. public class Meta {
public static void main(String[] args) {
System.out.println("public class Hello {");
System.out.println(" public static void main(String[] args) {");
System.out.println(" System.out.println(\"Hello, world!\");");
System.out.println(" }");
System.out.println("}");
}
}
7. public class Mantra {
public static void main(String[] args) {
message();
System.out.println();
message();
}
public static void message() {
System.out.println("There's one thing every coder must understand:");
System.out.println("The System.out.println command.");
}
}
8. // This program prints a message multiple times using static methods.
public class Stewie2 {
public static void main(String[] args) {
System.out.println("//////////////////////");
printVictory();
printVictory();
printVictory();
printVictory();
printVictory();
}
public static void printVictory() {
System.out.println("|| Victory is mine! ||");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
}
}
, 9. // Draws an egg figure.
public class Egg {
public static void main(String[] args) {
System.out.println(" _______");
System.out.println(" / \\");
System.out.println("/ \\");
System.out.println("-\"-'-\"-'-\"-");
System.out.println("\\ /");
System.out.println(" \\_______/");
}
}
10. // Draws several egg figures.
public class Egg2 {
public static void main(String[] args) {
drawEgg();
drawEgg();
drawBottom();
drawTop();
drawLine();
drawBottom();
}
public static void drawEgg() {
drawTop();
drawBottom();
drawLine();
}
public static void drawTop() {
System.out.println(" _______");
System.out.println(" / \\");
System.out.println("/ \\");
}
public static void drawBottom() {
System.out.println("\\ /");
System.out.println(" \\_______/");
}
public static void drawLine() {
System.out.println("-\"-'-\"-'-\"-");
}
}