题目是: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 }
运行后的截图如下