๋ฐ์ํ
๋ชฉํ
์ฝ๋
while ๋ฌธ ๋์ for๋ฌธ์ ํ์ฉํด๋ณด์๋ค.
package JavaFestival;
import java.util.Scanner;
public class test8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int fail = 0;
for(int i = 0; i < Math.pow(10,10000); i++) {
int temp1 = (int)(Math.random()*10);
int temp2 = (int)(Math.random()*10);
System.out.printf("%d + %d = ",temp1,temp2);
int ans = sc.nextInt();
if(ans == (temp1+temp2)) {
System.out.println("SUCCESS!");
}else {
System.out.println("Fail...");
fail++;
}
if(fail==5) break;
}
System.out.println("GAME OVER!");
}
}
๊ฒฐ๊ณผ
9 + 2 = 11
SUCCESS!
3 + 4 = 7
SUCCESS!
8 + 7 = 15
SUCCESS!
6 + 3 = 9
SUCCESS!
2 + 8 = 10
SUCCESS!
0 + 5 = 1
Fail...
0 + 5 = 2
Fail...
0 + 5 = 3
Fail...
7 + 9 = 4
Fail...
2 + 3 = 5
SUCCESS!
8 + 1 = 9
SUCCESS!
6 + 2 = 8
SUCCESS!
6 + 4 = 10
SUCCESS!
1 + 4 = 5
SUCCESS!
4 + 6 = 10
SUCCESS!
6 + 8 = 14
SUCCESS!
7 + 5 = 12
SUCCESS!
4 + 1 = 5
SUCCESS!
3 + 1 = 4
SUCCESS!
6 + 0 = 6
SUCCESS!
4 + 1 = 5
SUCCESS!
2 + 0 = 2
SUCCESS!
9 + 8 = 17
SUCCESS!
7 + 8 = 0
Fail...
GAME OVER!
๋ฐ์ํ