将数据存储在集合遍历

P1046 [NOIP2005 普及组] 陶陶摘苹果

su000916 @ 2023-07-13 16:01:28

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DEmo {
    public static void main(String[] args) {
        int temp = 0;
        int bd = 30;
        Scanner sc = new Scanner(System.in);
        List<Integer> ints = new ArrayList<Integer>();
        //10个苹果离地面的高度
        for(int i = 0 ; i < 10 ; i++){
            ints.add(sc.nextInt());
        }
        //淘淘手伸直的最大高度
        int tt = sc.nextInt();
        int MAX_tt = tt + bd;

        for (Integer integer :ints){
            if (integer <= MAX_tt){
                temp++;
            }
        }
        System.out.println(temp);

    }
}

by InversionShadow @ 2023-07-13 16:12:29

tlqtj,jbl


|