임계치룰
2026년 2월 23일 14:46분
package com.jesusbornd.exodus;
import java.util.ArrayList;
import java.util.List;
public class Exodus_36_Chapter_Lv3 {
public static class Collector {
private final List<Integer> amounts = new ArrayList<Integer>();
public void add(int amount) {
if (amount > 0) amounts.add(amount);
}
public int total() {
int sum = 0;
for (int i = 0; i < amounts.size(); i++) sum += amounts.get(i);
return sum;
}
public boolean enough(int need) {
return total() >= need;
}
}
public static void main(String[] args) {
Collector c = new Collector();
c.add(30);
c.add(40);
c.add(50);
int need = 100;
System.out.println("total=" + c.total());
System.out.println("enough=" + c.enough(need));
}
}
class Collector:
def __init__(self):
self.amounts = []
def add(self, amount: int):
if amount > 0:
self.amounts.append(amount)
def total(self) -> int:
s = 0
for a in self.amounts:
s += a
return s
def enough(self, need: int) -> bool:
return self.total() >= need
c = Collector()
c.add(30)
c.add(40)
c.add(50)
need = 100
print("total=", c.total())
print("enough=", c.enough(need))
Search
Categories
← 목록으로
Comments
작은 입력이 모여 결과가 되는 흐름이 인상적입니다.