반응형
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+"개 입니다.");
}
}
반응형
'IT > Programming' 카테고리의 다른 글
[JAVA] 흐름 제어문(for, while) 사용 예제 (0) | 2023.04.21 |
---|---|
[JAVA] Array(배열) 사용 예제 (0) | 2023.04.21 |
[JAVA] 배열을 활용한 점수입력 후 성적출력 프로그램 예제 (0) | 2023.04.21 |
[JAVA] nextLine 사용 예제 (0) | 2023.04.21 |
[JAVA] selection sort(선택 정렬) 예제 (0) | 2023.04.21 |