홀수 합 구하기
홀수의 합이 100까지 얼마나 빨리 커지는지 알고 싶으신가요? 이를 계산하는 코드를 직접 작성해 보세요.
이 연습은 강의의 일부입니다
중급 Java
연습 안내
- 루프를 만들기 위해 올바른 키워드를 입력하세요.
- 도달한
total을 저장할 적절한 변수를 사용하세요. - 매 반복마다
i가 2씩 증가하도록 알맞은 연산을 사용하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
class Adder {
public static void main(String[] args) {
int total = 0;
int i = 1;
// Enter the correct keyword to create the loop
____ (total < 100) {
// Call the appropriate variable to store the total reached
____ += i;
// Use the fitting operation to have i increase by 2 each run
i ____ 2;
}
System.out.println("We reach " + total + " when summing up to " + i);
}
}