STUDY/ㅡㅡ^
아 진짜 짱나는 문제 scanner-중첩for
by hingu
2024. 5. 3.
package oop;
import java.util.Scanner;
public class oop22 {
public static void main(String[] args) {
oop22_box oop22 = new oop22_box();
Scanner sc = new Scanner(System.in);
System.out.println("첫번째 입력값? : ");
int num1 = sc.nextInt();
System.out.println("두번째 입력값? : ");
int num2 = sc.nextInt();
System.out.println("세번째 입력값? : ");
String str = sc.next();
sc.close();
oop22.calc(num1, num2, str);
}
}
class oop22_box {
public void calc(int a, int b, String c){
int w;
if(c.equals("홀수")) {
w=1;
}else {
w=0;
}
int f1,f2;
int result = 0;
for(f1=a; f1<=b; f1++) {
for(f2=1; f2<=9; f2++) {
result = f1*f2;
if(result%2 == w) {
System.out.printf("%s * %s = %s%n",f1,f2,f1*f2);
}
}
}
}
}