IT/Programming / / 2023. 4. 21. 17:45

[JAVA] 구구단 4단, 30~100 누적합, 1~10000수 중 11과13의 공배수 예제

반응형
package dayday5;

import javax.swing.JOptionPane;

public class QUIZ01 {
		public static void main(String[] args) {
			/*
			 * 1. 구구단 4단을 출력하는 것
			 * 2. 30~100까지 누적합
			 * 3.1~10000까지 수중 11과 13의 공배수 판별 및 갯수 출력
			 */
			String str = JOptionPane.showInputDialog("구구단 몇단?");
			int i = Integer.parseInt(str);
			String str2 = JOptionPane.showInputDialog("1~부터 몇까지의 공배수를 구할 것 입니까?");
			int i2 = Integer.parseInt(str2);
			int count = 0 ;
			
			
			System.out.println("1. 구구단 "+i+"단을 출력하는 것");
			for(int j = 1 ; j <= 9 ; j++){
				System.out.println(i + " x " + j + " = " + i*j);
			}
			System.out.println();
			
			int sum = 0;
			System.out.println("2. 30~100까지 누적합");
			for(int k = 30 ; k <= 100 ; k++){
				sum += k;
				System.out.println("카운트 : "+ (++count));
			}
			System.out.println("답"+sum);
			System.out.println();
			
			System.out.println("3.1~"+i2+"까지 수중 11과 13의 공배수 판별 및 갯수 출력");
			count = 0;
			
			for(int n = 1 ; n <=i2 ; n++){
				if(n%11==0 && n%13==0){
					count+=1;
					System.out.println(n+"은 공배수입니다. "+"카운트 : "+count);
				}
			}
			JOptionPane.showMessageDialog(null, "공배수의 총 갯수는 \n"+count+"개 입니다.");
		}
}
반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유