public class Practice4 {
public static void main(String [] args){
Scanner input = new Scanner (System.in);
System.out.println("请输入三个整数:");
String str = input.next();
String [] tem = new String [100];
tem = str.split(" ");
int [] arr = new int [100];
for(int i = 0;i<tem.length;i++){
arr [i] = Integer.parseInt(tem [i]);
System.out.println(arr [i]);
}
}
分享到:更多
------解决方案-------------------- input.nextLine();
import java.util.Scanner;
public class Practice4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入三个整数:");
String str = input.nextLine(); // 这里用nextLine
String[] tem = new String[100];
tem = str.split(" ");
int[] arr = new int[100];
for (int i = 0; i < tem.length; i++) {
arr[i] = Integer.parseInt(tem[i]);
System.out.println(arr[i]);
}
}
}
------解决方案--------------------
import java.util.Scanner ;
public class Practice4{
public static void main(String [] args){
Scanner input = new Scanner (System.in);
System.out.println("请输入三个整数:");
String str = input.next();
String [] tem = str.split(",");
int [] arr = new int [100];
for(int i = 0;i<tem.length;i++){
arr [i] = Integer.parseInt(tem [i]);
System.out.println(arr [i]);
}
}
}