본문 바로가기
스마트인재개발원/자바

[자바]반복문 - 이중for문 구구단 출력

by 죠졍니 2022. 9. 14.
728x90
반응형
SMALL

<이중for>

 

예제1. 2~9단까지 모두 출력

 

 

import java.util.Scanner;

public class Ex09_이중for문1 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		for(int i=2;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				System.out.println(i +"*"+ j + "=" + i*j);
			}
			
		}
		
	}

}

 

 

import java.util.Scanner;

public class Ex10_이중for문2 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		
		for(int i=2;i<=9;i++) {
			System.out.print(i+"단 : ");
			
			for(int j=1;j<=9;j++) {
				System.out.print(i +"*"+ j + "=" + i*j+"\t");
			}
			System.out.println();
			
		}
		
	}

}

 

 

import java.util.Scanner;

public class Ex10_이중for문2 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		
		
		
			for(int k=1;k<=9;k++) {
				for(int i=2;i<=9;i++) {
					System.out.print(i +"*" +k+ "=" + i*k +"\t");
					
				}
				System.out.println();
			}
			
			
			
		}
		
	

}

 

 

 

 

 

 

728x90
반응형
LIST