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
- mybatis
- 생성자
- Graphic
- AWT
- JSP
- 에러페이지
- Spring
- Eclips
- 어노테이션
- 기본
- 클래스
- Menu
- 메소드
- 국제화
- Android
- HTML
- struts2
- 오버로딩
- 안드로이드
- OGNL
- 전화걸기
- 예외처리
- paint
- oracle
- layout
- Java
- 배열
- 메서드
- JavaScript
- 이클립스
Archives
- Today
- Total
note
for문 본문
public class For02 {//for문 public static void main(String[] args){ int i; //변수 선언 // 초기식 조건식 증감식 변수선언을 여기서 하면은 for문내에서만작동 // 하기 때문에 위에서 선언함 for(i=1; i<=4; i++)//{ 중괄호 생략 for문 시작 System.out.println(i ); //제어변수 i 값 출력 //} 중괄호 생략 (한줄일 경우 생략가능) System.out.println("---> " + i); } }
1
2
3
4
---> 5
변수 호출 영역
int a =3
for(int i =4)
i호출 가능
a호출가능
i호출 불가
public class For06 {//for문 public static void main(String[] arg){ int i; //제어변수 선언 int total =0; //합을 누적할 변수 total을 선언하고0으로초기화 for(i=1; i<=5; i++) //제어변수 i가 1부터 5까지 1씩증가하도록함 total +=i; //total = total + i; System.out.println("i ~ " + (i-1) + " = " + total); } }
i ~ 5 = 15
2단 출력
public class For04 {//for문으로 2단출력 public static void main(String[] args){ int i; //제어변수 선언 int a=2; //출력할 단을 저장하는 변수 선언, 2단 출력 System.out.println("<<-----" + a + "단---->>"); for(i=1; i<=9; i++) System.out.println(a + " * " + i + " = " + (a * i)); } }
<<-----2단---->>
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2중 for 문으로 구구단 출력
public class GuguDanTest { //2중 for문으로 구구단 public static void main(String[] arg){ for(int i=1; i<=9; i++){ for(int j=2; j<=9; j++){ int result = j * i; System.out.print(j+"*"+i+"="+result+"\t"); } //System.out.print("\n"); System.out.println();//개행 } } }