1. Input Method:
1 Traditional input methods:
Public classMainrun {/** * @paramargs*/ Public Static voidMain (string[] args) {Try{BufferedReader Strin=NewBufferedReader (NewInputStreamReader (system.in)); System.out.print ("Please enter a string:"); String Str=Strin.readline (); System.out.println ("First one:" +str); System.out.println ("Please enter a second string:"); String str2=Strin.readline (); System.out.println ("2nd one:" +str2); } Catch(IOException e) {e.printstacktrace (); } } } View Code
2, 1.5 after the scanner to:
Note the difference between next () and nextline (), where the former is distinguished by a space, while nextline () is distinguished by a newline character.
ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {String a= "word"; String b= "word"; intMaxstringlength = 0; Scanner SC=NewScanner (system.in); A=Sc.nextline (); b=Sc.nextline (); for(inti = 0; I < a.length (); i + +) for(intsize = 1; size <= a.length ()-I; Size + +) {String subString= A.substring (i, i +size); if(B.contains (subString) && Maxstringlength <size) {Maxstringlength=size; }} System.out.println (Maxstringlength); }}View Code
Java Basic Knowledge points