標籤:play view 傳統 lap try max gif amp buffer
1、輸入方式:
1傳統的輸入方式:
public class MainRun { /** * @param args */ public static void main(String[] args) { try { BufferedReader strin=new BufferedReader(new InputStreamReader(System.in)); System.out.print("請輸入一個字串:"); String str = strin.readLine(); System.out.println("第一個:"+str); System.out.println("請輸入第二個字串:"); String str2 = strin.readLine(); System.out.println("第2個:"+str2); } catch (IOException e) { e.printStackTrace(); } } } View Code
2、1.5後的Scanner來:
注意的是next()和nextLine()的區別,前者是以空格為區分,而nextLine()則是以分行符號為區分的
import java.util.Scanner;public class Main { public static void main(String[] args) { String a = "word"; String b = "word"; int maxStringLength = 0; Scanner sc = new Scanner(System.in); a = sc.nextLine(); b = sc.nextLine(); for(int i = 0 ; i < a.length() ; i ++) for(int size = 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 基礎知識點