반응형
import java.io.*;
public class Plus {
public static void main(String[] ar) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("수를 입력하세요 : ");
int x = Integer.parseInt(in.readLine());
int tot = 0;
for(int a= 1; a <= x; a++) {
tot += a; // tot = tot + a;
}
System.out.print("1에서 " + x + "까지의 합은 " + tot + "입니다.");
}
}
public class Plus {
public static void main(String[] ar) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("수를 입력하세요 : ");
int x = Integer.parseInt(in.readLine());
int tot = 0;
for(int a= 1; a <= x; a++) {
tot += a; // tot = tot + a;
}
System.out.print("1에서 " + x + "까지의 합은 " + tot + "입니다.");
}
}
반응형
'JAVA > JAVA Programming' 카테고리의 다른 글
[JAVA] 2개의 수를 구하고 그중 큰 수에서 뽑아낸 랜덤값과 작은 수의 결과가 같은지를 확인 (0) | 2012.01.06 |
---|---|
[JAVA] A부터 Z까지 나타내기 (0) | 2012.01.06 |
[JAVA] 성적 처리 프로그램 (0) | 2012.01.04 |
[JAVA] Calender 클래스 활용 (0) | 2012.01.04 |
[JAVA] 배열 (0) | 2012.01.04 |