Java中怎么在一行中输入指定个数的数字,数字之间用空格隔开【原创】


题目是:Java中怎么在一行中输入指定个数的数字,数字之间用空格隔开

编写之后的结果是:

 1 package test;
 2 
 3 import java.util.Scanner;
 4 
 5 public class ShuChuZhiDingGeShu {
 6     public static void main(String[] args) {
 7         Scanner sc = new Scanner(System.in);
 8         System.out.print("number:");
 9         int n = sc.nextInt();
10         sc.close();
11         for (int i = 0; i < n; i++) {
12             System.out.print(i + 1 + " ");
13         }
14     }
15 
16 }
展开看源码

运行后的截图如下

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM