Last login: Wed Aug 26 07:20:19 on ttys000

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) MAC:Wed Aug 26:08:46:Downloads> cd
(base) MAC:Wed Aug 26:08:46:~> cd 20202021/T1
(base) MAC:Wed Aug 26:08:46:T1> ls
4240          Num.class     firstDayA.txt firstDayF.txt
4260          Num.java      firstDayB.txt why.txt
(base) MAC:Wed Aug 26:08:46:T1> cd 4260
(base) MAC:Wed Aug 26:08:46:4260> jshell
|  Welcome to JShell -- Version 14.0.1
|  For an introduction type: /help intro

jshell> int whole = 5;
whole ==> 5

jshell> byte b = (byte) whole
b ==> 5

jshell> b
b ==> 5

jshell> whole = 551
whole ==> 551

jshell> byte b  = (byte) whole
b ==> 39

jshell> Integer.toString(551, 2)
$6 ==> "1000100111"

jshell> Integer.toString(39, 2)
$7 ==> "100111"

jshell> //downcasting

jshell> b
b ==> 39

jshell> int y = b;
y ==> 39

jshell> byte c = 551
|  Error:
|  incompatible types: possible lossy conversion from int to byte
|  byte c = 551;
|           ^-^

jshell> int foo = (int) true;
|  Error:
|  incompatible types: boolean cannot be converted to int
|  int foo = (int) true;
|                  ^--^

jshell> boolean maybe = (boolean) 1
|  Error:
|  incompatible types: int cannot be converted to boolean
|  boolean maybe = (boolean) 1;
|                            ^

jshell> (int) 'q'
$10 ==> 113

jshell> (char) 45
$11 ==> '-'

jshell> (int) 5.26
$12 ==> 5

jshell> (int) -5.26
$13 ==> -5

jshell> double d = 4;
d ==> 4.0

jshell> long ell = 3243434234;
|  Error:
|  integer number too large
|  long ell = 3243434234;
|             ^

jshell> long ell = 3243434;
ell ==> 3243434

jshell> (double) ell
$16 ==> 3243434.0

jshell> String s = "hello"
s ==> "hello"

jshell> // + concatenates strings

jshell> String num = "567";
num ==> "567"

jshell> (int) num
|  Error:
|  incompatible types: java.lang.String cannot be converted to int
|  (int) num
|        ^-^

jshell> int n = Integer.parseInt(num);
n ==> 567

jshell> n
n ==> 567

jshell> String avocado = "6.02e23"
avocado ==> "6.02e23"

jshell> double a = Double.parseDouble(avocado);
a ==> 6.02E23

jshell> /import
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*

jshell> ArrayList<String> al = new ArrayList<>();
al ==> []

jshell> al.add("oink");
$24 ==> true

jshell> al
al ==> [oink]

jshell> al.add("moo")
$26 ==> true

jshell> al.add("baaaa");
$27 ==> true

jshell> al.add("blahooo")
$28 ==> true

jshell> al
al ==> [oink, moo, baaaa, blahooo]

jshell> al[0]
|  Error:
|  array required, but java.util.ArrayList<java.lang.String> found
|  al[0]
|  ^---^

jshell> al.get(0)
$30 ==> "oink"

jshell> al.get(2)
$31 ==> "baaaa"

jshell> al.get(4)
|  Exception java.lang.IndexOutOfBoundsException: Index 4 out of bounds for length 4
|        at Preconditions.outOfBounds (Preconditions.java:64)
|        at Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
|        at Preconditions.checkIndex (Preconditions.java:248)
|        at Objects.checkIndex (Objects.java:373)
|        at ArrayList.get (ArrayList.java:426)
|        at (#32:1)

jshell> //change oink to snuffle

jshell> al.set(0, "snuffle);
|  Error:
|  unclosed string literal
|  al.set(0, "snuffle);
|            ^

jshell> al.set(0, "snuffle");
$33 ==> "oink"

jshell> al
al ==> [snuffle, moo, baaaa, blahooo]

jshell> String evictee = al.set(0, "oink");
evictee ==> "snuffle"

jshell> al
al ==> [oink, moo, baaaa, blahooo]

jshell> evicteee
|  Error:
|  cannot find symbol
|    symbol:   variable evicteee
|  evicteee
|  ^------^

jshell> evictee
evictee ==> "snuffle"

jshell> /quit
|  Invalid command: /quit
|  Type /help for help.

jshell> /exit
|  Goodbye
(base) MAC:Wed Aug 26:09:17:4260> !j
jshell
|  Welcome to JShell -- Version 14.0.1
|  For an introduction type: /help intro

jshell> String s = "hello"
s ==> "hello"

jshell> s.toUpperCase()
$2 ==> "HELLO"

jshell> s.toLowerCase()
$3 ==> "hello"

jshell> s.length()
$4 ==> 5

jshell> s.substring(1)
$5 ==> "ello"

jshell> s.substring(1,3)
$6 ==> "el"

jshell> s.substring(1,5)
$7 ==> "ello"

jshell> s.charAt(5)
|  Exception java.lang.StringIndexOutOfBoundsException: String index out of range: 5
|        at StringLatin1.charAt (StringLatin1.java:48)
|        at String.charAt (String.java:711)
|        at (#8:1)