Created
January 18, 2015 15:16
-
-
Save komo91/5f2a10916b1dd162584a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class ContinueSample1 { | |
public static void main(String[] args) { | |
Random rn = new Random(); | |
Scanner sc = new Scanner(System.in); | |
System.out.println("計算します。"); | |
System.out.println("足し算・引き算・掛け算の順番です。"); | |
System.out.println("各3問ずつ出題されます。"); | |
System.out.println("各問題で最初の2問を連続で正解すると次にいけます。"); | |
int count = 0; | |
int count2 = 0; | |
int kaisuu = 0; | |
int kotae = 0; | |
int seikai = 0; | |
kurikaesu:for(int i = 1; i <= 3; i++) { | |
for(int j = 1; j <= 3; j++) { | |
int mondai1 = 1 + rn.nextInt(100); | |
int mondai2 = 1 + rn.nextInt(100); | |
kaisuu++; | |
if(i == 1){ | |
System.out.println("----------足し算"); | |
System.out.print(mondai1 + "+" + mondai2 + "="); | |
kotae = sc.nextInt(); | |
seikai = (mondai1 + mondai2); | |
if(seikai == kotae) { | |
System.out.println("正解です。"); | |
count++; | |
count2++; | |
}else { | |
System.out.println("不正解です。"); | |
System.out.println("正解は:" + seikai); | |
} | |
} | |
if(count == 2) { | |
count = 0; | |
continue kurikaesu; | |
} | |
if(j == 3) { | |
count = 0; | |
}if(i == 2) { | |
System.out.println("----------引き算"); | |
System.out.println(mondai1 + "-" + mondai2 + "="); | |
kotae = sc.nextInt(); | |
seikai = (mondai1 - mondai2); | |
if(seikai == kotae) { | |
System.out.println("正解です。"); | |
count++; | |
count2++; | |
} else { | |
System.out.println("不正解です。"); | |
System.out.println("正解は" + seikai); | |
} | |
if(count == 2) { | |
count = 0; | |
continue kurikaesu; | |
} | |
if(j == 3) { | |
count = 0; | |
} | |
} | |
if(i == 3) { | |
System.out.println("----------掛け算"); | |
System.out.println(mondai1 + "*" + mondai2 + "="); | |
kotae = sc.nextInt(); | |
seikai = (mondai1 * mondai2); | |
if(seikai == kotae) { | |
System.out.println("正解です。"); | |
count++; | |
count2++; | |
} else { | |
System.out.println("不正解です。"); | |
System.out.println("正解は" + seikai); | |
} | |
if(count == 2) { | |
count = 0; | |
continue kurikaesu; | |
} | |
if(j == 3) { | |
count = 0; | |
} | |
} | |
} | |
} | |
System.out.println(kaisuu + "問中" + count2 + "問正解です。"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment