자바 반복문(Java repetitive statement) 예제

for문은 반복된 명령을 수행할 때 사용됩니다.

 

예제소스

public class h5bak_for {
    public static void main(String[] args) {
        int arrNum[] = { 11, 22, 33, 44, 55, 66 };
        for (int i = 0; i <= 10; i++) {
            System.out.println("출력 : " + i);
        }
        System.out.println("출력 끝");
        System.out.println("============================");
 
        for (int num : arrNum) { // 배열의 내용을 출력할 때 향상된 for문으로 간단하게 출력
            System.out.println("향상된 for : " + num);
        }
    }
}


실행결과

Posted by 준콩ol 준콩ol

댓글을 달아 주세요

  1. 뉴비개발자 2015.11.12 16:59  댓글주소  수정/삭제  댓글쓰기

    합격/불합격 여부를 checkbox로 체크하여 평가하기를 누를시 한번에 업데이트
    되는 기능을 구현 하려고 하고 있습니다.
    헌데 문제는 맨 앞에 row의를 합격 이라고 하면 1번부터 10번까지 모두 합격이 되는 것입니다...
    저는 밑에 그림과 같이 합격/불합격 을 개별적으로 체크해서 각각의 결과가 모두 업데이트가 되게끔 하고 싶은데
    check박스의 value 값들을 request.getparametervalues로 가져와서
    java 파일에서 for문으로 업데이트 하려는데 이게 해결이 안되서 질문좀 드리겠습니다.

    아래는 소스 코드 인데 for 문이 옳게 되어 있는건지 모르겠네요 ㅠ

    public void update(String deptno[], String dname[], String loc[]) {

    Connection con = null;
    PreparedStatement pstmt = null;

    try {

    con = DriverManager.getConnection(url, userid, passwd);
    for (int i = 0; i <= 3; i++) {
    String sql = "update g01 set deptno = ?, dname = ?, loc = ? where code = 01";
    pstmt = con.prepareStatement(sql);
    pstmt.setString(1, deptno[i]);
    pstmt.setString(2, dname[i]);
    pstmt.setString(3, loc[i]);
    pstmt.addBatch();
    }
    pstmt.executeBatch();
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    try {
    if (pstmt != null)
    pstmt.close();
    if (con != null)
    con.close();
    } catch (SQLException se) {

    se.printStackTrace();

    }
    }

    }