g0rez

第一种方法:(不限制输入数组的长度)

  System.out.println("请输入几个数并用逗号隔开:");
  Scanner sc = new Scanner(System.in);
  String str = sc.next().toString();
  String[] arr  = str.split(",");
  int[] b = new int[arr.length];
  for(int j = 0; j<b.length;j++) {
   b[j] = Integer.parseInt(arr[j]);
   System.out.println(b[j]+" ");
  }

第二种方法:(限制输入的个数)

System.out.println("请输入三个数:");
Scanner in = new Scanner(System.in);
int[] b=new int[3];
for(int i=0;i<b.length;i++){
b[i]=in.nextInt();
}

 

————————————————
版权声明:本文为CSDN博主「Baby~卓」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43157131/article/details/88126490

 

分类:

技术点:

相关文章:

  • 2020-01-30
  • 2022-12-23
  • 2021-09-28
  • 2021-10-12
  • 2021-11-19
猜你喜欢
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-09-25
  • 2022-12-23
  • 2021-11-21
相关资源
相似解决方案