Chapter 1 Computer science (1-15 textbook questions)
What are the two types of real number data types?
float and double
What does a statement typically ends with
semi-colon (;)
(pg.48) 8. What is the output produced from the following statements? System.out.println("\"Quotes\""); System.out.println("Slashes \\//"); System.out.println("How '\" confounding' \"\\\" it is!");
"Quotes" Slashes \// How '" confounding' "\" it is!
What is Boolean used for?
Determine if statement is true or false?
(pg. 55) 5. Write a complete Java program called MuchBetter that prints the following output: A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget: use \" instead of " : " " is not the same as "
Public class MuchBetter{ public static void main( ) { 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("with a " + '"' + " character. "); System.out.println("'" + "'" + " is not the same as " + '"');
10. What is the output produced from the following Statements? System.out.println("Shaq is 7'1"); System.out.println("The string \"\" is an empty message."); System.out.println("\\'\"\" ");
Shaq is 7'1 The string "" is an empty message. \'""
13. What series of println statements would produce the following output? "Several slashes are sometimes seen," said Sally. "I've said so." See? \ / \\ // \\\ / //
String a = "Several slashes are sometimes seen, "; String b = "I've said so."; System.out.println('"' + a + '"'); System.out.println("said Sally. " + '"' + b + '"' + " See?"); String fr = "//"; String ba = "\\"; System.out.print(fr.charAt(0) + " "); System.out.print(ba + " "); System.out.println( fr + " " + ba + ba + " " + fr + fr.charAt(0) + " " + ba + ba +ba + " ");
What's one type of IED?
Visual Studio, NetBeans, intelliJ
(pg.54) 1. Write a complete Java program called Stewie that prints the following output: //////////////////// | | Victory is mine | | \\\\\\\\\\\\\\\\\\\\
System.out.println("//////////////////////"); System.out.println("|| Victory is mine ||"); System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
7. Which of the following is correct syntax to output a message? a. System.println(Hello, world!); b. System.println.out('Hello, world!'); c. System.println("Hello, world!"); d. System.out.println("Hello, world!"); e. Out.system.println"(Hello, world!)";
d.
9. What is the output produced from the following statements? System.out.println("name\tage\theight"); System.out.println("Archie\t17\t5'9\" "); System.out.println("Betty\t17\t5'6\" "); System.out.println("\ \ ' \ " \" ");
name age height Archie 17 5'9" Betty 17 5'6" \'" "
What are bugs?
problems with code
24. What would have been the output of the preceding program if the third method had contained the following statements? public static void third() { first(); second(); System.out.println("Inside third method"); }
Would call first and second method and then print Inside third method Or Inside first method Inside second method Inside third method (if predicted by looking method 3 statement)
27. What would have been the output of the preceding program if the method3 method had contained the following statements? public static void method3 ( ) { method1( ); method2( ); System.out.println("I am method 3. ");
Would call method 1 and 2 and print I am method 3. or I am method 1 I am method 2 I am method 3 ( if predicted by looking method 3 statement)
(pg. 57) 13. Write a Java program called StarFigures that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. (check book for shape)
public class StarFigures{ public static void main( ) { straight(); x(); System.out.println(); straight(); x(); straight(); System.out.println(); System.out.println(" * "); System.out.println(" * "); System.out.println(" * "); straight(); x(); } public static void straight(){ System.out.println("*****"); System.out.println("*****"); } public static void x(){ System.out.println(" * *"); System.out.println(" * "); System.out.println(" * *"); } }
12. What is the output produced from the following Statements? System.out.println("Dear \"DoubleSlash\" magazine, "); System.out.println( ); System.out.println("\tYour publication confuses me. Is it"); System.out.println("a \\\\ slash or a //// slash?"); System.out.println("Susan\"Suzy\" Smith");
Dear "DoubleSlash" magazine, Your publication confuses me. Is it a \\ slash or a //// slash? Susan"Suzy" Smith
21. Which of the following method headers uses the correct syntax? a. public static example() { b. public static void example() { c. public void static example() { d. public static example void[ ] { e. public void static example { } {
b.
9. Write a program called Egg that displays the following output: (refer to image in textbook)
public class Egg{ public static void callTopline(){ System.out.println(" ________"); System.out.println(" / \\"); System.out.println("/ \\"); } public static void callBottomline(){ System.out.println("\\ /"); System.out.println(" \\________/"); } public static void callLine(){ System.out.println("-" + '"' + "-" + "'" + "-" + '"'+ "-" + "'" + "-" + '"' + "-"); } public static void main( ){ callTopline(); callLine(); callBottomline(); } }
(pg.55) 8. Write a complete Java program called Stewie2 that prints the following output. Use at least one static method beside main. //////////////////// | | Victory is mine | | \\\\\\\\\\\\\\\\\\\\ | | Victory is mine | | \\\\\\\\\\\\\\\\\\\\ | | Victory is mine | | \\\\\\\\\\\\\\\\\\\\ | | Victory is mine | | \\\\\\\\\\\\\\\\\\\\ | | Victory is mine | |
public class Stewie2 { public static void main() { Top(); Bottom(); Bottom(); Bottom(); Bottom(); Bottom(); } public static void Top( ) { System.out.println("//////////////////////"); } public static void Bottom( ) { System.out.println("|| Victory is mine ||"); System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"); }
(pg.54) 3. Write a complete Java program called WellFormed that prints the following output: A well-formed Java program has a main method with { and } braces. A System.out.println statement has { and } and usually a String that starts and ends with a " character. {But we type \" instead! }
public static void WellFormed{ public static void main() { 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! }"); } }