第7章課後作業


public class Homework4 {
public static void main(String[] args) {
int[] nums = new int[10];
int legalCount = 0 ; //合法數字個數
int illegalCount = 0 ; //非法數字個數
System.out.println("請輸入10個數字:");
Scanner input = new Scanner(System.in);
for (int i = 0; i < nums.length; i++) {
nums[i] = input.nextInt();
switch(nums[i]) {
case 1:
case 2:
case 3: legalCount++ ;
break ;
default:illegalCount++;
}
}
System.out.print("輸入的10個數爲:") ;
for(int i=0; i<nums.length; i++) {
System.out.print(nums[i] + " ");
}
System.out.print(num[j]+"");
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章