Advertisement
Guest User

Untitled

a guest
May 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class JPA05 {
  3. public static void main(String args[]) {
  4. Scanner input = new Scanner(System.in);
  5. int sum = 0, n = 0, num;
  6. System.out.println("請輸入10個整數:");
  7. int []arr = new int[10];
  8. for(int index=1;index<=10;index++) {
  9. System.out.print("第" + index + " 個整數:");
  10. num = input.nextInt();
  11. arr[index-1] = num;
  12. }
  13. for(int index=0;index<arr.length;index++) {
  14. if(arr[index] > 60) {
  15. n++;
  16. sum += arr[index];
  17. }
  18. }
  19. System.out.println("陣列中大於60的有" + n + "個\n總合為" + sum + "\n平均值為" + (sum / (double)n));
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement