Homework 01 is due today.

Submit something if you want to make up later. 

Reading assignment for Lab 03: Chapter 05.

Let's look at Problem P1.1 on page 28. 

Given two numbers n and m calculate the largest number. 

import java.util.Scanner;

public class Madison {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in); 
    System.out.print("First number: "); 
    int n = Integer.parseInt(in.nextLine());
    System.out.print("First number: "); 
    int m = in.nextInt(); 
    System.out.println( Math.max( n, m ) );
    if ( n >= m ) {
       System.out.println( n ); 
    } else {
       System.out.println( m ); 
    }
    System.out.println( ( n < m ) ? m : n ); 
    // Math.abs 2 + - / 
    System.out.println( (n + m + Math.abs(n - m)) / 2 );
  }
}

What is a type? 

A type is a set of values plus the operations defined on it. 

Examples: 

  int    + - % / 

  double 

  boolean = { true, false }

What operations do we have on booleans? 

Three operations: 

  !     negation      not 

  &&    conjunction   and 

  ||    disjunction   or 


   p     q        p && q    p || q     !q
-------------------------------------------- 
  true  true      true       true      false
  true  false     false      true      true 
  false true      false      true 
  false false     false      false 

If x is an integer the following expressions are equivalent:

  x + 0        x

  x * 0        0

  x * 1        x

Please simplify the following four expressions (boolean p, q;): 

 p == true           p 

 p     p == true     p
------------------------
true   true         true 
false  false        false 

 p || !p       simplifies to    true 

 p && !p       simplifies to    false 


 p == false          


 p     p == false     !p  
----------------------------
true   false          false 
false  true           true