본문 바로가기

프로그래밍/자바소스 및 자료

[자바소스] 구구단 출력 프로그램(for문 사용)


1. 소스 설명
 for문을 사용한 구구단 출력 프로그램입니다.
while문을 사용한 구구단 출력 프로그램과 동일합니다.


2.소스 : P1.java 파일입니다.
import java.util.Scanner;

public class P1 {
 public static void main(String[] args){
  Scanner input=new Scanner(System.in);
  System.out.println("구구단 프로그램입니다.");
  System.out.print("단수를 입력하세요. : ");
  int number=input.nextInt();
  
  for(int i=1; i<10; i++)
   System.out.printf("%s * %s = %s\n", number, i, number*i);
 }
}



3.결과