Last login: Thu Mar 24 10:37:43 on ttys004 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:Thu Mar 24:10:53:~> jshell | Welcome to JShell -- Version 17.0.1 | For an introduction type: /help intro jshell> String.format("%s is chasing %s\n", "The cat", "the mouse.") $1 ==> "The cat is chasing the mouse.\n" jshell> System.out.println($1) The cat is chasing the mouse. jshell> // jshell> String s = "hellohello"; s ==> "hellohello" jshell> s.indexOf("l") $4 ==> 2 jshell> s.indexOf("o", 5) $5 ==> 9 jshell> s.lastIndexOf("o"); $6 ==> 9 jshell> s.lastIndexOf("o", 8) $7 ==> 4 jshell> s.indexOf("llo") $8 ==> 2 jshell> s.indexOf('l'); $9 ==> 2 jshell> s.indexOf('z'); $10 ==> -1 jshell> //obi above jshell> ////ana jshell> String s="abc" s ==> "abc" jshell> s.replace("a", "b") $12 ==> "bbc" jshell> s.replace('a', 'b') $13 ==> "bbc" jshell> s.replace('a', "b") | Error: | no suitable method found for replace(char,java.lang.String) | method java.lang.String.replace(char,char) is not applicable | (argument mismatch; java.lang.String cannot be converted to char) | method java.lang.String.replace(java.lang.CharSequence,java.lang.CharSequence) is not applicable | (argument mismatch; char cannot be converted to java.lang.CharSequence) | s.replace('a', "b") | ^-------^ jshell> s s ==> "abc" jshell> s.contains("a") $15 ==> true jshell> s.contains("bc") $16 ==> true jshell> s.contains("cow") $17 ==> false jshell> // Evan jshell> s s ==> "abc" jshell> s.toUpperCase(); $19 ==> "ABC" jshell> s = s.toUpperCase(); s ==> "ABC" jshell> s.toLowerCase(); $21 ==> "abc" jshell> String s = new String(" hmmmmmm ") s ==> " hmmmmmm " jshell> s.strip() $23 ==> "hmmmmmm" jshell> s.stripLeading() $24 ==> "hmmmmmm " jshell> s.stripTrailing() $25 ==> " hmmmmmm" jshell> s s ==> " hmmmmmm " jshell> s = " \n " s ==> " \n " jshell> s.isBlank() $28 ==> true jshell> "".isBlank() $29 ==> true jshell> String.format("%sppy birth%s!!", "Ha", "day") $30 ==> "Happy birthday!!" jshell> String.format("%sppy birth%s!!", "Ha", 42) $31 ==> "Happy birth42!!" jshell> String.format("H%sppy birth%s!!", "a", 42) $32 ==> "Happy birth42!!" jshell> String.format("%s%s", "goof") | Exception java.util.MissingFormatArgumentException: Format specifier '%s' | at Formatter.format (Formatter.java:2688) | at Formatter.format (Formatter.java:2625) | at String.format (String.java:4140) | at (#33:1) jshell> String.format("%s%s", "goof", "ball) | Error: | unclosed string literal | String.format("%s%s", "goof", "ball) | ^ jshell> String.format("%s%s", "goof", "ball") $34 ==> "goofball" jshell>