65-lecture09 - Computer Science 65 Intro to CS February 21,...

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

View Full Document Right Arrow Icon
Computer Science 65 Intro to CS February 21, 2008 Comparing Strings (Section 3.6) Switch Statements (Section 3.9) Do-While Loops (Section 4.4)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements For Tuesday Read Chapter 3.6, 3.9, 4.4, 4.7 Assignment #4 Due
Background image of page 2
Homework #4 beware Entering a String after entering a number may cause a problem
Background image of page 3

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

View Full DocumentRight Arrow Icon
Homework #4 beware Entering a String after entering a number may cause a problem Reason: the keyboard.nextInt() method does not “officially” read in the newline character generated by pressing the enter key nextInt() does retrieve the next integer pressed, so if you keep on prompting for integers, your program will be fine
Background image of page 4
Problem with reading Strings after ints How to fix it After you read in an integer via keyboard.nextInt(), follow the next line with keyboard.nextLine() to consume the newline character
Background image of page 5

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

View Full DocumentRight Arrow Icon
Today is a Catch-up Day Comparing Strings (Section 3.6) Switch Statement (Section 3.9) Do-While Loops (Section 4.4)
Background image of page 6
More Loop Exercises You get paid 1 penny your first day of work, 2 pennies the second day of work, 3 pennies the third day of work, etc. Calculate the number of pennies you have earned after 100 days
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Comparing String Objects Section 3.6 In java there are two different types of variables Primitive data types Objects Variables derived from pre-defined Classes
Background image of page 11

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

View Full DocumentRight Arrow Icon
Comparing Variables For primitive data types, we can use the familiar relational expressions <, >, >=, <= int x = 54; int y = 54; if (x == y) { System.out.println(“they’re equal -- Hooray!!”); } For objects, however, this (typically) won’t work … why not?
Background image of page 12
notes
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
What will be the result? Rectangle r1 = new Rectangle(10,20);
Background image of page 17

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

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

This note was uploaded on 04/02/2008 for the course CS 065 taught by Professor Urness during the Spring '08 term at Drake University .

Page1 / 35

65-lecture09 - Computer Science 65 Intro to CS February 21,...

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

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