http://gufeng99.lofter.com/post/1d146f3d_69c623b
Scanner in = new Scanner(System.in);
System.out.println("请输入一串整数并在输入时用英文逗号隔开:");
String inputString = in.next();
String[] stringArray = inputString.split(",");
int[] nums=new int[stringArray.length];
for(int i=0;i<stringArray.length;i++){
nums[i]=Integer.parseInt(stringArray[i]);
System.out.print(nums[i]+" ");
}
in.close();
运行效果如下:
请输入一串整数并在输入时用英文逗号隔开:
2,4,5,34,2,21
2 4 5 34 2 21
热门评论
写得很棒诶!👍