{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

JavaBasicsPractice - 15-121 Introduction to Data Structures...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
15-121: Introduction to Data Structures Fall 2009 Exercise 08/27/2009 Java Basics Practice Due: none Relevant Reading: Chapters 1-5 of the online text by Eck. Basics in Java notes linked from course calendar. Readings about Java basics in other references you may have (eg. the Pohl download) Assignment: (worth 0 exercise points - this is for practice only 1) What do each of the following expressions evaluate to in Java? Feel free to type them in and find out. a) 22 / 7 b) 22 % 7 c) 7 / 22 d) 7 % 22 e) 10 * 6 / 9 f) 10 * (6 / 9) g) 10.0 * 6 / 9 h) 10.0 * (6 / 9) i) 10 + 5 * 9 j) 10 * 5 + 9 2) Assume the following skeleton of a program. public class Application { public static void main(String [] args) { int i = 10; double pi = 3.14159; int a = 0, b=0; char c = 'X'; double f = 0.0, g = 0.0; boolean x = true, y = true; // snippets go here } } For each of the following snippets to be inserted where indicated above, indicate the ouput (in the console/terminal window) when the program is run. If the snippet does not compile, say so and why. Each snippet is intended to be taken SEPARATELY. Try to guess each answer, then use the computer to verify that you were correct. Ask questions of things you don't understand. a) a = 5; System.out.println(a); System.out.println(b); b) a = i * 5; System.out.println(a); System.out.println(i); c) i = a * 5; System.out.println(a); System.out.println(i);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
d) f = 5.3; a = f * 2; System.out.println(a); System.out.println(f); e) a = 10; c = 'a'; // note single quotes System.out.println(a); System.out.println(c); f) a = 'c'; // note single quotes System.out.println(a); System.out.println(c); g) a = 10; c = "a"; // note double quotes System.out.println(a); System.out.println(c); h) c = 'A'; System.out.println(c + 1); System.out.println(c + c); i) c = 'B'; System.out.println(c + 1); System.out.println(c + c); j) a = 10; c = a; System.out.println(a); System.out.println(c); k) a = 10; b = a * 2; a = 6; System.out.println(a); System.out.println(b); l) a = 10; f = a * 2; a = 6; System.out.println(a); System.out.println(f); m) a = 10; b = 3; a = a + 2; System.out.println(a); System.out.println(b); n) a = 10; b = a + 5; a = a + 2; System.out.println(a); System.out.println(b); o) x = true; y = false; System.out.println(x);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}