-bash-4.2$ cat Program.java
// if I have two numbers (integers) n and m
// how do you calculate the largest of the two?

public class Program {
  public static void main(String[] args) {
    int result = Program.max(3, 5);
    System.out.println("The largest number is: " + result);
  }
  public static int max(int n, int m) {
    if (n < m)
      return m;
    else
      return n;
  }
}
-bash-4.2$ javac Program.java
-bash-4.2$ ls -l
total 8
-rw-r--r-- 1 dgerman faculty 748 Aug 26 19:52 Program.class
-rw-r--r-- 1 dgerman faculty 368 Aug 26 19:52 Program.java
-bash-4.2$ java Program
The largest number is: 5
-bash-4.2$ 

Now we want to not use if statements. 

-bash-4.2$ cat Math.java
public class Math {
  public static void main(String[] args) {
    int result = java.lang.Math.max(5, 3);
    System.out.println( result );
  }

}
-bash-4.2$

Here's using Math.max from a class not called Math (and without Math in this folder).

-bash-4.2$ ls
Program.class  Program.java
-bash-4.2$ javac Program.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java Program
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest number is: 5
-bash-4.2$ cat Program.java
// if I have two numbers (integers) n and m
// how do you calculate the largest of the two?

public class Program {
  public static void main(String[] args) {
    int result = Math.max(5, 3); // 3, 5);
    System.out.println("The largest number is: " + result);
  }
}
-bash-4.2$

Now the idea: 

              (n+m)/2

-------+--------|--------+------

The distance between n and m is |n - m| / 2

   the largest of the two can be calculated as

          (n + m + |n - m|) / 2 

In Java: 

       (n + m + Math.abs(n - m)) / 2


-bash-4.2$ cat Program.java
// if I have two numbers (integers) n and m
// how do you calculate the largest of the two?

public class Program {
  public static void main(String[] args) {
    int result = Program.max(-6, -7);
    System.out.println("The largest number is: " + result);
  }
  public static int max(int n, int m) {
    return ( n + m + Math.abs( n - m )) / 2;
  }
}
-bash-4.2$ javac Program.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java Program
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest number is: -6
-bash-4.2$

So now let's show you how to use command line arguments:

-bash-4.2$ cat Program.java

public class Program {
  public static void main(String[] args) {
    int first = Integer.parseInt( args[0] );
    int second = Integer.parseInt( args[1] );
    int result = Program.max(first, second);
    System.out.println("The largest between " + first + " and " + second + " is: " + result);
  }
  public static int max(int n, int m) {
    return ( n + m + Math.abs( n - m )) / 2;
  }
}
-bash-4.2$ javac Program.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java Program 16 42
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest between 16 and 42 is: 42
-bash-4.2$ java Program 42 16
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest between 42 and 16 is: 42
-bash-4.2$ java Program -6 -7
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest between -6 and -7 is: -6
-bash-4.2$ java Program -7 -6
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
The largest between -7 and -6 is: -6
-bash-4.2$

Be careful how you calculate: 


-bash-4.2$ ls
Program.class  Program.java
-bash-4.2$ cat Program.java
public class Program {
  public static void main(String[] args) {
    int first = Integer.parseInt( args[0] );
    int second = Integer.parseInt( args[1] );
    int result = Program.max(first, second);
    System.out.println("The largest between " + first + " and " + second + " is: " + result);
  }
  public static int max(int n, int m) {
    return ( n + m ) / 2 + Math.abs( n - m ) / 2;
  }
}
-bash-4.2$ javac Program.java
-bash-4.2$ java Program 3 5
The largest between 3 and 5 is: 5
-bash-4.2$ java Program 5 3
The largest between 5 and 3 is: 5
-bash-4.2$ java Program -6 8
The largest between -6 and 8 is: 8
-bash-4.2$ java Program 11 23
The largest between 11 and 23 is: 23
-bash-4.2$ java Program 23 11
The largest between 23 and 11 is: 23
-bash-4.2$ java Program 4 2
The largest between 4 and 2 is: 4
-bash-4.2$ java Program 6 6
The largest between 6 and 6 is: 6
-bash-4.2$ java Program -4 -2
The largest between -4 and -2 is: -2
-bash-4.2$ java Program 10 0
The largest between 10 and 0 is: 10
-bash-4.2$ java Program 6 -4
The largest between 6 and -4 is: 6
-bash-4.2$ java Program -4 4
The largest between -4 and 4 is: 4
-bash-4.2$ java Program 1 4    <--------------(a-ha!)------
The largest between 1 and 4 is: 3
-bash-4.2$ java Program 3 4
The largest between 3 and 4 is: 3
-bash-4.2$ java Program 3 10
The largest between 3 and 10 is: 9
-bash-4.2$

In Java what is (2 + 3) / 2? 

Surprisingly the answer is: 2.

And the reason is: integer division. 

-bash-4.2$ cat Program.java
public class Program {
  public static void main(String[] args) {
    System.out.println( "1 + 2 = " + (1 + 2) ); // 3
    System.out.println( (1 + 2) / 2 ); // how many 2's fit into 3
    System.out.println( 3 / 7 ); // 0
    System.out.println( 13 / 7 ); // 1

    System.out.println( "3 / 2 = " + (3 / 2) ); // 1
    System.out.println( 1 / 2.0 ); // 0.5

  }
}
-bash-4.2$

--

18:48:10     From  Dion Daggy : dion daggy
18:48:12     From  Danny Reidinger : Danny Reidinger
18:48:12     From  Alexander Ausbrook : Alexander Ausbrook
18:48:12     From  kevinrivera : Kevin Rivera
18:48:12     From  Denys Moroz : denys moroz
18:48:12     From  Rui Zhang  to  dgerman@iu.edu(Privately) : Rui Zhang
18:48:13     From  Jiahao Wu : Jiahao Wu
18:48:13     From  nonaanderson : Nona Anderson
18:48:13     From  Ryan McDonough : Ryan McDonough
18:48:14     From  Oscar Pullam : Oscar Pullam
18:48:15     From  Alison Dwyer : Alison Dwyer
18:48:15     From  Robert Kellems : Robert Kellems
18:48:15     From  Dhruv Purohit : Dhruv Purohit
18:48:16     From  Colleen Lee : Colleen Lee
18:48:17     From  Luke Williams : Luke Williams
18:48:18     From  Riley Campbell : Riley Campbell
18:48:18     From  Yunping Wang : Yunping Wang
18:48:18     From  Lizzy Gabel : Elizabeth Gabel
18:48:19     From  Michael Liu : Michael Liu
18:48:19     From  Colin Hans : Colin Hans
18:48:19     From  Austin Bond : Austin Bond
18:48:19     From  JD Anderson : JD Anderson 
18:48:19     From  Sam Shi : Samuel Shi
18:48:20     From  Tareq Hanania : Tareq Hanania
18:48:21     From  Sheng Hu : Sheng Hu
18:48:22     From  Colin Myers : Colin Myers
18:48:37     From  Tareq Hanania : Was that guy earlier actually in the course?
18:48:42     From  Drew Beasley : Drew Beasley 
18:48:42     From  tyson : Tyson Miller
18:48:43     From  kevinrivera : No lol
18:48:52     From  MaxwellRodriguez : Max Rodriguez
18:49:05     From  Andrew Fritz : Andrew Fritz
18:49:06     From  Christopher Hill : Christopher Hill
18:50:56     From  Lizzy Gabel  to  dgerman@iu.edu(Privately) : Jack Kelly isn't technically in the class yet he said
18:51:06     From  Lizzy Gabel  to  dgerman@iu.edu(Privately) : but he was in lecture for the past 2 classes
18:53:28     From  Sam Shi : for some reason i can’t hear
18:56:44     From  Lizzy Gabel : you can rename in this class, or you can log into a zoom account and change you official name
18:59:01     From  Lizzy Gabel : it was fine, lol
19:03:22     From  Denys Moroz : rip
19:06:53     From  Jiahao Wu : my mic broke
19:07:07     From  Jiahao Wu : sry my mic broke
19:07:50     From  Jiahao Wu : I took C200
19:11:13     From  Lizzy Gabel : I'm in the dorms and fire alarm just went off
19:11:18     From  Lizzy Gabel : So I have to go
19:11:32     From  Lizzy Gabel : Hopefully I'll be back soon
19:12:24     From  Nona Anderson : Be safe! If you can’t get back, this is still being recorded, so you’ll be able to access the material either way.
19:16:05     From  Lizzy Gabel : I'm back!
19:16:34     From  sandy : where do you find silo?
19:16:43     From  Rui Zhang : Please try to sign in to silo rn
19:16:47     From  Lizzy Gabel : it's in the putty thing
19:16:50     From  Oscar Pullam : Open putty
19:16:51     From  Rui Zhang : install putty in windows
19:16:54     From  Tareq Hanania : What is the host name
19:16:57     From  Tareq Hanania : silo.?
19:16:58     From  Dhruv Purohit : I have downloaded puTTy but I don't know how to go from there
19:17:01     From  Rui Zhang : or terminal on mac and linux
19:17:08     From  Oscar Pullam : silo.soic.indiana.edu
19:17:11     From  Lizzy Gabel : silo.cs.indiana.edu I think
19:17:13     From  Colin Myers : I am in the same boat as Dhruv
19:17:19     From  Rui Zhang : ssh username@silo.cs.indiana.edu

19:17:34     From  Rui Zhang : you can also use ssh command with cmd on windows
19:18:35     From  Rui Zhang : ssh username@silo.soic.indiana.edu

19:19:36     From  Dhruv Purohit : It will not let me type at the password screen, what should I do?
19:19:48     From  Lizzy Gabel : It is letting you type
19:19:53     From  Lizzy Gabel : it just doesn't show the characters
19:19:55     From  Rui Zhang : it should be entered
19:19:56     From  Nona Anderson : The text is hidden
19:19:59     From  Nona Anderson : ^ yes
19:20:00     From  Dhruv Purohit : Okay thank you
19:20:01     From  Rui Zhang : just not showing up
19:20:03     From  manas : where do I write this program?
19:20:24     From  Rui Zhang : in Linux, use editors like nano
19:20:26     From  manas : me
19:23:37     From  Tareq Hanania : can u scroll back up 
19:23:51     From  Danny Reidinger : how do you create the folder?
19:23:56     From  Dhruv Purohit : ^
19:24:02     From  Rui Zhang : mkdir dirname
19:24:04     From  MaxwellRodriguez : ^
19:29:43     From  Denys Moroz : it says denied for me?
19:30:21     From  Nona Anderson : what’s the exact message it’s sending you?
19:30:21     From  Rui Zhang : which step are you in
19:31:20     From  Denys Moroz : End of keyboard-interactive prompts from server
Access denied
Keyboard-interactive authentication prompts from server:
| Password:
| Password:

19:31:44     From  Rui Zhang : Are you sure you have entered the correct password?
19:31:56     From  Nona Anderson : It should be the same one as your iu account
19:32:34     From  Denys Moroz : it worked nvm
19:32:45     From  Nona Anderson : great
19:35:00     From  Dhruv Purohit : To save our work here, do we just hit ctrl+s, or do we do something else?
19:35:13     From  Rui Zhang : ctrl + o
19:35:15     From  Rui Zhang : enter
19:35:21     From  Rui Zhang : ctrl + x 
19:35:45     From  Rui Zhang : ctrl + o : write
enter : confirm file name
ctrl + x : exit

19:35:50     From  manas : what do I do after I install putty
19:36:31     From  Danny Reidinger : you use: silo.cs.indiana.edu
19:38:26     From  Denys Moroz : well now its saying software caused connection abort n it wont let me type
19:39:30     From  Rui Zhang : can you try to reconnect to silo?
19:39:51     From  Nona Anderson : Yeah I’d say maybe reset it or exit/reenter
19:40:51     From  manas : what do I type on window command in SSH options
19:41:36     From  Nona Anderson : Could you clarify
19:41:40     From  manas : can I do the same thing on ecplise?
19:41:45     From  Riley Campbell : Use an if statement?
19:41:46     From  Lizzy Gabel : conditional statements?
19:41:47     From  Tareq Hanania : if else statements
19:41:55     From  Lizzy Gabel : boolean
19:41:58     From  Tareq Hanania : boolean
19:43:56     From  Lizzy Gabel : quick question: are spaces between variable name and equal sign required, or is that preference
19:45:02     From  Lizzy Gabel : is camel case ok with you guys?
19:50:18     From  Tareq Hanania : built in functions
19:50:26     From  Tareq Hanania : max()
19:50:56     From  Dhruv Purohit : Search Method that stores the first number then replaces it with higher numbers once read, then returns final value
19:51:53     From  Lizzy Gabel : sorry, I forgot the syntax to return to the file
19:52:04     From  Nona Anderson : nano filename
19:52:14     From  Nona Anderson : Or nano -w filename
19:52:53     From  manas : do we have to turn in anything for the lab?
20:00:51     From  Tareq Hanania : if we change the public class to a different name can we then use it without java.lang?
20:04:45     From  Tareq Hanania : How do we turn it in?
20:05:52     From  Colleen Lee : Do we turn it in to silo?
20:06:05     From  Colleen Lee : Or do we turn it in to Canvas?
20:06:24     From  Colleen Lee : Thank you
20:07:52     From  sandy : so canvas?
20:08:03     From  Nona Anderson : canvas, Prof. German will show you how
20:09:26     From  Dhruv Purohit : Ascii table?
20:11:56     From  Lizzy Gabel : sorry, will you post readings soon?
20:17:45     From  sandy : what happens to the program if they are equal values
20:18:06     From  Nona Anderson : That’s something you take into account with the code
20:18:08     From  Nona Anderson : good question
20:19:10     From  Nona Anderson : In terms of what happens to the program, that’s a situation that is much more beneficial to test yourself- helps you get familiar with the language and how to code carefully surrounding similar situations
20:21:57     From  Alexander Ausbrook : Ic an compile all my programs correctly, but I keep getting errors like this:
20:22:12     From  Alexander Ausbrook : Error: Could not find or load main class Example.class
20:22:33     From  Danny Reidinger : just type Example
20:22:41     From  Danny Reidinger : don't use Example.class
20:22:49     From  Nona Anderson : ^ use Example.java
20:22:50     From  Alexander Ausbrook : thanks,
20:22:54     From  Nona Anderson : Example.class is for the computer
20:23:02     From  Lizzy Gabel : order of operations is messed up
20:23:23     From  Tareq Hanania : 0 and 0 ? 
20:26:45     From  Dhruv Purohit : 4 2
20:26:54     From  Tareq Hanania : the same numbers?
20:26:56     From  Danny Reidinger : -4 and -2
20:28:07     From  Lizzy Gabel : have we tried only one negative number, but the second number is the negative one
20:28:23     From  Lizzy Gabel : yes
20:28:38     From  Riley Campbell : -4 4
20:28:50     From  Lizzy Gabel : does it work with decimals?
20:28:55     From  Sheng Hu : 1 and 4
20:30:37     From  Dhruv Purohit : Dividing by 2 makes the decimals chop off and round lower?
20:30:43     From  Dhruv Purohit : if odd
20:31:36     From  Lizzy Gabel : 2.5
20:31:38     From  Dhruv Purohit : 2
20:38:45     From  Colleen Lee : When is the due date of this lab?
20:38:55     From  MaxwellRodriguez : Next week
20:38:56     From  Dhruv Purohit : Will the submission be in Canvas for this lab?
20:39:45     From  Lizzy Gabel : how do we submit the stuff from silo to canvas?
20:39:56     From  Lizzy Gabel : Do we just copy-paste?
20:40:26     From  Dhruv Purohit : And can we use any method to maximize when submitting the lab?
20:41:07     From  Tareq Hanania : how do we fix the absolute value function we created to account for odd sums of the 2 numbers we choose
20:44:19     From  Lizzy Gabel : okay
20:45:38     From  MaxwellRodriguez : Have a great night!
20:53:40     From  Rui Zhang : please share your screen instead of individual windows
20:58:53     From  Nona Anderson : silo.cs.indiana.edu
21:01:26     From  Rui Zhang  to  dgerman@iu.edu(Privately) : https://www.nasa.gov/image-feature/ice-scours-the-north-caspian-sea

--