lecture05 - Computer Science 65 Intro to CS February 7,...

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

View Full Document Right Arrow Icon
Computer Science 65 Intro to CS February 7, 2008 Keyboard Input If statements Dialog Boxes
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 Assignment #2 due today (now) Difficulty of course starts to increase Most students earning As last semester stopped by my office You’re going to get stuck Start assignments early Don’t get frustrated There are a lot of rules for java Don’t need to memorize all of the rules Exams: page of notes Text book is a good resource
Background image of page 2
Announcements Programming Style There is more than one way to program “Why did you re-use a variable?” “Couldn’t I create a new variable here?”
Background image of page 3

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

View Full DocumentRight Arrow Icon
Today’s Lecture Keyboard Input (2.13) If statements (3.1) Dialog Boxes (2.14)
Background image of page 4
Reading Keyboard Input System.out is sufficient for outputting data to the console System.in only reads input as byte values (not very intuitive) Scanner class is designed to read input from the keyboard in an easier fashion Not automatically available to Java programs import java.util.Scanner; //beginning of the file
Background image of page 5

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

View Full DocumentRight Arrow Icon
Creating a Scanner Scanner keyboard = new Scanner(System.in); Declares a variable named keyboard. The variable can reference an object of the Scanner class Creates a Scanner object in memory. The object will read input from System.in (the keyboard)
Background image of page 6
Scanner Example import java.util.Scanner; public class KeyboardInput { public static void main(String[] args) { int favoriteNumber; Scanner keyboard = new Scanner(System. in ); System. out .println("What is your favorite number?"); favoriteNumber = keyboard.nextInt(); System. out .println("Your favorite number is " + favoriteNumber); } }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Operations for reading keyboard input String str; int i; double var; str = keyboard.nextLine(); i = keyboard.nextInt(); var = keyboard.nextDouble();
Background image of page 8
What Can We Do? What’s Next?
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
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 / 34

lecture05 - Computer Science 65 Intro to CS February 7,...

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

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