Week6Chap4-III

Week6Chap4-III - Chapter 4 Control Statements in Java...

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

View Full Document Right Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Chapter 4 Control Statements in Java Selection
Background image of page 1

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

View Full DocumentRight Arrow Icon
Selection : Quick Recap Janaka Balasooriya CSE 110, Arizona State University
Background image of page 2
Janaka Balasooriya CSE 110, Arizona State University One Way Selection expression statement Java code (syntax): if (logical expression) statement (s) Example: int myNumber; Scanner keyboard = new Scanner (System.in); myNumber =keyboard.nextInt(); if(myNumber < 0) Sytem.out.println (“a negative number”); True False
Background image of page 3

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

View Full DocumentRight Arrow Icon
Janaka Balasooriya CSE 110, Arizona State University Two way selection expression statement Java code (syntax): if (expression) statement else statement Example: int myNumber; Scanner keyboard = new Scanner (System.in); myNumber; =keyboard.nextInt(); if(myNumber < 0) Sytem.out.println (“a negative number”); else Sytem.out.println (“a positive number”); statement True False
Background image of page 4
Using Selection: Examples Janaka Balasooriya CSE 110, Arizona State University
Background image of page 5

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

View Full DocumentRight Arrow Icon
Selection Example: Wages.java //******************************************************************** // Wages.java Java Foundations // // Demonstrates the use of an if-else statement. //******************************************************************** import java.text.NumberFormat; import java.util.Scanner; public class Wages { //----------------------------------------------------------------- // Reads the number of hours worked and calculates wages. //----------------------------------------------------------------- public static void main (String[] args) { final double RATE = 8.25; // regular pay rate final int STANDARD = 40; // standard hours in a work week Scanner scan = new Scanner (System.in); double pay = 0.0; (more…)
Background image of page 6
4.2 – Wages.java
Background image of page 7

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

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

This note was uploaded on 12/08/2010 for the course CSE 110 taught by Professor Kim during the Spring '08 term at ASU.

Page1 / 18

Week6Chap4-III - Chapter 4 Control Statements in Java...

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

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