所有计算机的语言,用户操作都是围绕着:输入和输出设计的。
直接敲一遍下面的代码即可。记得敲一个情况,一个注释哦
import java.util.Scanner;
public class ACM {
public static void main(String[] args) {
// 输入接收器
Scanner scanner = new Scanner(System.in);
// 不同的类型接收
byte next1 = scanner.nextByte();
short next2 = scanner.nextShort();
int next3 = scanner.nextInt();
long next4 = scanner.nextLong();
float next5 = scanner.nextFloat();
double next6 = scanner.nextDouble();
String next7 = scanner.next();
boolean next8 = scanner.nextBoolean();
// 输入一个字符串,接受一行数据,将其作为一个字符串返回
String str = scanner.nextLine();
// 输入一行数据,然后打印
while (scanner.hasNext()) {
System.out.println(scanner.nextInt());
}
// 字符串
while(scanner.hasNext()){
String s = scanner.nextLine();
String[] split = s.split(",");
for (String str : split) {
System.out.println(s);
}
int[] num = new int[split.length];
for (int i = 0; i < split.length; i++) {
num[i] = Integer.parseInt(split[i]);
System.out.println(num[i]);
}
}
// 输入两行,第一行输入N表示第二行的个数,如N=3,第二行是1,2,3.
int len = scanner.nextInt();
int[] num = new int[len];
for (int i = 0; i < len; i++) {
num[i] = scanner.nextInt();
System.out.println(num[i]);
}
// 二维数组,矩阵接收数据
int row = scanner.nextInt();
int col = scanner.nextInt();
int[][] dp = new int[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
dp[i][j] = scanner.nextInt();
}
scanner.nextLine();
}
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.println(dp[i][j]);
}
}
// 测试 next nextLine
while (scanner.hasNext()) {
// String s = scanner.nextLine();
String s = scanner.nextLine();
System.out.println(s);
}
}
}