Last login: Tue Mar 22 09:19:54 on ttys008 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. MAC:Tue Mar 22:09:21:~> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> x =5 >>> y = 3 >>> x*y 15 >>> ^D MAC:Tue Mar 22:09:33:~> jshell | Welcome to JShell -- Version 17.0.1 | For an introduction type: /help intro jshell> int x = 4 x ==> 4 jshell> x*x $2 ==> 16 jshell> $2 + x $3 ==> 20 jshell> /vars | int x = 4 | int $2 = 16 | int $3 = 20 jshell> "amanaplanacanalpanama" $4 ==> "amanaplanacanalpanama" jshell> /vars | int x = 4 | int $2 = 16 | int $3 = 20 | String $4 = "amanaplanacanalpanama" jshell> /list 1 : int x = 4; 2 : x*x 3 : $2 + x 4 : "amanaplanacanalpanama" jshell> int p = 1 p ==> 1 jshell> p *= 1048576 $6 ==> 1048576 jshell> p p ==> 1048576 jshell> p *= 1048576 $8 ==> 0 jshell> p *= 1048576 $9 ==> 0 jshell> p p ==> 0 jshell> int big = Integer.MAX_VALUE; big ==> 2147483647 jshell> big + 1 $12 ==> -2147483648 jshell> # int is a 32 bit two's complement integer. | Error: | illegal character: '#' | # int is a 32 bit two's complement integer. | ^ | Error: | ';' expected | # int is a 32 bit two's complement integer. | ^ jshell> // int is a 32 big two's complement integer jshell> long y = 1; y ==> 1 jshell> y y ==> 1 jshell> y *= 1048576; $15 ==> 1048576 jshell> y y ==> 1048576 jshell> y *= 1048576; $17 ==> 1099511627776 jshell> y *= 1048576; $18 ==> 1152921504606846976 jshell> y *= 1048576; $19 ==> 0 jshell> Long.MAX_VALUE $20 ==> 9223372036854775807 jshell> Byte b = 0; b ==> 0 jshell> while(b > 0){b++;} jshell> b b ==> 0 jshell> b b ==> 0 jshell> while(b >= 0){b++;} jshell> b b ==> -128 jshell> //byte is a one-byte integer jshell> short s = 0; s ==> 0 jshell> while(s >= 0){s++;} jshell> s s ==> -32768 jshell> Byte.MAX_VALUE $30 ==> 127 jshell> Byte.MIN_VALUE $31 ==> -128 jshell> // byte (1 byte), short(2 bytes), int(4 bytes), long(8 bytes). jshell> byte q = 1 q ==> 1 jshell> byte r = 1 r ==> 1 jshell> byte s = q + r | Error: | incompatible types: possible lossy conversion from int to byte | byte s = q + r; | ^---^ jshell> 3 + 5 $34 ==> 8 jshell> 3*5 $35 ==> 15 jshell> 4 - 6 $36 ==> -2 jshell> 365/7 $37 ==> 52 jshell> 365 % 7 $38 ==> 1 jshell> //integer division is the default for integers. jshell> jshell> 48*3 < 150 $39 ==> true jshell> //Java has a boolean type, bool jshell> boolean q = 2 + 2 == 4; q ==> true jshell> q q ==> true jshell> 2.0/8 $42 ==> 0.25 jshell> .1 + .1 +.1 == .3 $43 ==> false jshell> .1 + .1 +.1 $44 ==> 0.30000000000000004 jshell> .3 $45 ==> 0.3 jshell> (double) 5 $46 ==> 5.0 jshell> (int) 5.34 $47 ==> 5 jshell> (int) -5.34 $48 ==> -5 jshell> Math.floor(-5.34) $49 ==> -6.0 jshell> int bomb = 4.5; | Error: | incompatible types: possible lossy conversion from double to int | int bomb = 4.5; | ^-^ jshell> byte b = 675 | Error: | incompatible types: possible lossy conversion from int to byte | byte b = 675; | ^-^ jshell> byte b = (byte)675; b ==> -93 jshell> byte b = (byte)676; b ==> -92 jshell> // downcasting: It can leave you downcast. jshell> Float.MAX_VALUE $52 ==> 3.4028235E38 jshell> Double.MAX_VALUE $53 ==> 1.7976931348623157E308 jshell> String s = "hello" s ==> "hello" jshell> s.charAt(0) $55 ==> 'h' jshell> String t = s.charAt(0); | Error: | incompatible types: char cannot be converted to java.lang.String | String t = s.charAt(0); | ^---------^ jshell> char ch = 'a'; ch ==> 'a' jshell> ch++ $57 ==> 'a' jshell> ch ch ==> 'b' jshell> ch++ $59 ==> 'b' jshell> chc | Error: | cannot find symbol | symbol: variable chc | chc | ^-^ jshell> ch ch ==> 'c' jshell> (int) ch $61 ==> 99 jshell> (char) 945 $62 ==> 'α' jshell> (char) 946 $63 ==> 'β' jshell> (char) 947 $64 ==> 'γ' jshell> (char) 949 $65 ==> 'ε' jshell> (char) 948 $66 ==> 'δ' jshell> (char) 5545 $67 ==> 'ᖩ' jshell> (char) 8223 $68 ==> '‟' jshell> (char) 2211 $69 ==> 'ࢣ' jshell> String s = "this is a string. It can be very long"; s ==> "this is a string. It can be very long" jshell> s.charAt(4) $71 ==> ' ' jshell> int quack = 6; quack ==> 6 jshell> quack.foo() | Error: | int cannot be dereferenced | quack.foo() | ^-------^ jshell>