JavaBasicsPractice

JavaBasicsPractice - 15-121 Introduction to Data StructuresFall 2009ExerciseJava Basics PracticeDue none Relevant Reading:•Chapters 1-5 of the

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-121: Introduction to Data StructuresFall 2009Exercise08/27/2009Java Basics PracticeDue: 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);d) f = 5.3;a = f * 2;System.out.println(a);System.out.println(f);e) a = 10;c = 'a'; // note single quotesSystem.out.println(a);System.out.println(c);f) a = 'c'; // note single quotesSystem.out.println(a);System.out.println(c);g) a = 10;c = "a"; // note double quotesSystem.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);System....
View Full Document

This document was uploaded on 12/19/2009.

Page1 / 6

JavaBasicsPractice - 15-121 Introduction to Data StructuresFall 2009ExerciseJava Basics PracticeDue none Relevant Reading:•Chapters 1-5 of the

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online