Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 서버설정
- 자료구조와함께배우는알고리즘입문
- 이터레이터
- 데비안
- 친절한SQL튜닝
- network configuration
- 코드로배우는스프링웹프로젝트
- 네트워크 설정
- /etc/network/interfaces
- 목록처리
- 코드로배우는스프링부트웹프로젝트
- 스프링부트핵심가이드
- 처음 만나는 AI 수학 with Python
- ㅒ
- 자료구조와 함께 배우는 알고리즘 입문
- 자바편
- 스프링 시큐리티
- d
- iterator
- 처음 만나는 AI수학 with Python
- Kernighan의 C언어 프로그래밍
- 선형대수
- 알파회계
- 티스토리 쿠키 삭제
- baeldung
- 구멍가게코딩단
- GIT
- 페이징
- resttemplate
- 리눅스
Archives
- Today
- Total
bright jazz music
01-4 반복 본문
정수 n까지의 합 구하기
//내가 짠 코드
import java.util.Scanner;
public class TestMain {
public static void main(String[] args){
Scanner stdin = new Scanner(System.in);
System.out.println("숫자 입력: ");
int n = stdin.nextInt();
int sum = 0;
for(int i=1; i <= n; i++){
sum = sum + i;
}
System.out.println(sum);
}
}
import java.util.Scanner;
public class TestMain {
public static void main(String[] args){
Scanner stdin = new Scanner(System.in);
System.out.println("숫자 입력: ");
int n = stdin.nextInt();
int sum = 0;
int i = 1;
while (i <= n){
sum = sum + i;
i++;
}
System.out.println(sum);
}
}
'Algorithm&Data structure > Java text book' 카테고리의 다른 글
01-6 연습문제 (0) | 2022.12.02 |
---|---|
01-3 순서도( flow chart) (0) | 2022.09.05 |
01-2 중앙값(median) 구하기 (0) | 2022.09.03 |
01-1 최댓값/최솟값 구하기 (0) | 2022.09.02 |
Comments