您可以根据需求使用下列任意选项。importjava.util.Scanner;Scannerscan=newScanner(System.in);Strings=scan.next();inti=scan.nextInt();importjava.io.BufferedReader;importjava.io.InputStreamReader;BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
Strings=br.readLine();inti=Integer.parseInt(br.readLine());importjava.io.DataInputStream;DataInputStreamdis=newDataInputStream(System.in);inti=dis.readInt();
这个readLine方法的DataInputStream班弃用..要获得字符串值,您应该在BufferedReader中使用前面的解决方案importjava.io.Console;Consoleconsole=System.console();Strings=console.readLine();inti=Integer.parseInt(console.readLine());
显然,这种方法在某些IDE中效果不佳。