• 티스토리 홈
  • 프로필사진
    chantleman
  • 방명록
  • 공지사항
  • 태그
  • 블로그 관리
  • 글 작성
chantleman
  • 프로필사진
    chantleman
    • 분류 전체보기 (328)
      • 프로젝트 (1)
      • react (2)
      • 코딩테스트 (133)
        • lv0 (101)
        • lv1 (10)
        • lv2 (7)
        • lv3 (15)
      • 오류 (14)
      • 리눅스 (5)
      • 자바 (75)
        • spring (7)
      • js (35)
      • 오라클 (39)
        • PLSQL (3)
      • cs (5)
      • 도커 aws (3)
      • 단축키 (3)
      • 나만봐 (0)
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • 이중 for문 예제
        2024년 07월 08일
        • chantleman
        • 작성자
        • 2024.07.08.:47

        1   2    3    4

        5   6    7    8

        9  10  11  12

        13 14 15  16

         

        for(int i=0;i<4;i++)
        {
        	for(int j=0;j<4;j++)
        	{
        		int result=i*4+j+1;
        		System.out.print(result+"\t");
        	}
        	System.out.println();
        	}
        }

         


        1   2    3    4

        8   7    6    5

        9  10  11  12

        16 15 14  13

        for(int i=0;i<4;i++)
        {
        	if((i+1)%2==1)
        	{
        		for(int j=0;j<4;j++)
        		{
        			int result = i*4+j+1;
        			System.out.print(result+"\t");
        		}		
        	}
        	else {	
        		for(int j=3;j>=0;j--)
        		{
        			int result= i*4+j+1;					
        			System.out.print(result+"\t");
        		}				
        	}
        		System.out.println();
        			
        	}
          }
        for(int i=0;i<4;i++)
        {
        	for(int j=0;j<4;j++)
        	{
        		int result=0;
        		if(i%2==0) result= i*4+j+1;
        		if(i%2==1) result = i*4+4-j;
        		System.out.print(result +"\t");
        	}
        	System.out.println();
        }

         


        1  5  9  13

        2  6  10 14

        3  7  11  15

        4  8  12  16

        for(int i=0;i<4;i++)
        {
        	for(int j=0;j<4;j++)
        	{
        		int result=i+j*4+1;
        		System.out.print(result+"\t");
        	}
        	System.out.println();	
        }

         

        1  8  9  16
        2  7  10 17
        3  6  11 14
        4  5  12 13

         

        for(int i=0;i<4;i++)
        {
        	for(int j=0;j<4;j++)
        	{
        		int result=0;
        		if(j%2==0) result=i+j*4+1;
        		else result=-i+j*4+4;
        		System.out.print(result+"\t");
        	}
        	System.out.println();
        }

         

        *
        **
        ***
        ****

        System.out.print("row입력: ");
        int row=sc.nextInt();
        for(int i=0;i<row;i++)
        {
        	for(int j=0;j<i+1;j++)
        	{
        		System.out.print("*");
        	}
        	System.out.println();
        }

         

           *

          **
         ***
        ****

        System.out.print("row입력: ");
        		int row=sc.nextInt();
        		
        for(int i=0;i<row;i++)
        {
        	for(int space=0;space<row-1-i;space++)
        	{
        		System.out.print(" ");
        	}
        	for(int star=0;star<i+1;star++)
        	{
        		System.out.print("*");
        	}
        	System.out.println();
        }

         

         

        ****   
        *** 
        **
        *

        System.out.print("row입력: ");
        int row=sc.nextInt();
        for(int i=0;i<row;i++)
        {
        	for(int j=0;j<=row-i-1;j++)
        	{
        		System.out.print("*");
        	}
        	System.out.println();
        }

         

        ****   
         *** 
          **
           *

        System.out.print("row입력: ");
        int row=sc.nextInt();
        for(int i=0;i<row;i++)
        {
        	for(int space=0;space<i;space++)
        	{
        		System.out.print(" ");
        	}
        	for(int star=0;star<row-i;star++)
        	{
        		System.out.print("*");
        	}
        	System.out.println();
        }

         

            *   
           *** 
          *****
         *******

        System.out.print("row입력: ");
        int row=sc.nextInt();
        		
        for(int i=0;i<row;i++)
        {
        	for(int space=row-i;space>=0;space--)
        	{
        		System.out.print(" ");
        	}
        	for(int star=0;star<i*2+1;star++)
        	{	
        		System.out.print("*");
        	}
        	System.out.println();
        }

         

        *******    
         ***** 
          ***
           *

        System.out.print("row입력: ");
        int row=sc.nextInt();		
        for(int i=0;i<row;i++)
        {
        	for(int space=0;space<i;space++)
        	{
        		System.out.print(" ");
        	}
        	for(int star=0;star<(row-i-1)*2+1;star++)
        	{
        		System.out.print("*");
        	}
        	System.out.println();
        }

         


         

        *   * 
         * *
          *
         * *

        *   *

        int n=5;
        for(int i=0;i<n;i++)
        {
        	for(int j=0;j<n;j++)
        	{
        		if(j==i || j==n-i-1)
        		{
        			System.out.print("*");
        		}
        		else
        		{
        			System.out.print(" ");
        		}
        	}
        			
        	System.out.println();
        }
        728x90

        '자바' 카테고리의 다른 글

        스택, 힙, equals(), ==  (0) 2024.07.10
        for문 break, continue  (0) 2024.07.09
        시와 분을 입력받고 30분 뒤, 30분 전 시간 출력하는 예제  (0) 2024.07.05
        대문자 소문자로 바꾸기 예제  (2) 2024.07.03
        String 타입 변환  (2) 2024.07.03
        다음글
        다음 글이 없습니다.
        이전글
        이전 글이 없습니다.
        댓글
      조회된 결과가 없습니다.
      스킨 업데이트 안내
      현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
      ("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
        • 안녕하세요
        • 감사해요
        • 잘있어요

        티스토리툴바