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