題目是: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 }
運行后的截圖如下