Java输入和输出数组(加逗号)
输入示例
6 |
输出示例
1,2,3,4,5,6 |
1 import java.util.Scanner; 2 public class Demo01 { 3 public static void main(String[] args) { 4 Scanner sc = new Scanner(System.in); 5 int n=sc.nextInt(); 6 String str = sc.next().toString(); 7 String[] arr = str.split(","); 8 int[] b = new int[n]; 9 for (int j = 0; j < n; j++) { 10 b[j] = Integer.parseInt(arr[j]); 11 if(j!=n-1) 12 System.out.print(b[j] + ","); 13 else 14 System.out.println(b[j]); 15 } 16 System.out.print(arr[0]); 17 for(int i=1;i<arr.length;i++){ 18 System.out.print(","+arr[i]); 19 }
sc.close(); 20 } 21 }