Howdy.

In two weeks we have the first exam. 

https://www.cs.indiana.edu/classes/c212-dgerman/sum2018/exams/exam01-6w2-sum2018.pdf

Chapter 4 (for today)

Chapter 5 (Monday)

Chapter 6 (next Wednesday)

--

Exam will cover only the first six chapters (without Graphics). 

This week in lab you create GitHub accounts, respond to invites etc.

We want you to move everything to GitHub for Monday and then we will
try to post all grades for all assignments based is on GitHub by Wed. 

-bash-4.2$ cat One.java
public class One {
  public static void main(String[] args) {

    System.out.println( 1 );
    System.out.println( 1 + 2 );
    System.out.println( 1 < 2 );

    int a = 3; // local variable

    int b; // initialize before use

    boolean c;

    c = 4 < 3; // false



  }
}
-bash-4.2$ javac One.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
1
3
true
-bash-4.2$

boolean = { true, false }

operators for booleans: && (and), || (or), ! (not)

   a     b       !a     a && b     a || b 
---------------------------------------------
  true  true    false   true       true 
  true  false           false      true 
  false true    true    false      true 
  false false           false      false 

! is like unary minus

&& is like *

|| is like + 

R5.30 p. 223 assumes 

  boolean b = false;
  int x = 0; 
  System.out.println( b && x != 0 ); 

-bash-4.2$ cat One.java
public class One {
  public static void main(String[] args) {

    // R5.30 p. 223 assumes

    boolean b = false;
    int x = 0;

    System.out.println( b && x != 0 ); // predict: false

    x = 1;

    System.out.println( b || x != 0 ); // predict: true
                           // true
                 // false || true
  }
}
-bash-4.2$

Now 5.31 (a) 

simplify   b == true 

zach proposes: b

a simplified expression is an equivalent expression that is "simpler" (shorter)

what word in English becomes shorter when you add two letters to it

what word in English becomes shorter when you add three letters to it  

  b     b == true    b
-------------------------------
 true   true         true 
 false  false        false 

and 5.31 (b) 

simplify   b == false 

zach proposes: !b 

5.32 (b) 

simplify

   if (n == 0) { b = false; } else { b = true; } 

-bash-4.2$ nano -w One.java
-bash-4.2$ javac One.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(-5, -39) = -5
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(-19, -2) = -2
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(13, -26) = 13
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(-37, -28) = -28
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(39, 47) = 47
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(33, 8) = 32
-bash-4.2$


-bash-4.2$ cat One.java
public class One {
  public static void main(String[] args) {

    int n = (int)(Math.random() * 100 - 50),
        m = (int)(Math.random() * 100 - 50);

    System.out.print("The largest of(" + n + ", " + m + ") = ");

    int martinsville = (n + m) / 2;

    int largest = martinsville + Math.abs(n - m) / 2;

    System.out.println( largest );

  }
}
-bash-4.2$

-bash-4.2$ cat One.java
public class One {
  public static void main(String[] args) {

    int n = (int)(Math.random() * 100 - 50),
        m = (int)(Math.random() * 100 - 50);

    System.out.print("The largest of(" + n + ", " + m + ") = ");

    int martinsville = (n + m) / 2;

    int largest = martinsville + Math.abs(n - m) / 2;

    System.out.println( largest );

  }
}
-bash-4.2$ nano -w One.java
-bash-4.2$ javac One.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(-43, -38) = -38
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest of(-35, 21) = 21
-bash-4.2$

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> int i = 3
> i
3
> i + 1
4
> i
3
> i++
3
> i
4
> ++i
5
> i
5


Assume i is 5 

(a) what gets printed by

    System.out.println( i++ + ++i )

    and what's the value of i at the end. 

(b) what's the value of i after this statement: 

    i = ++i + i++;


(c) what is the value of 

    i++ < i