Skip to content

Instantly share code, notes, and snippets.

@komo91
Created January 18, 2015 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komo91/5f2a10916b1dd162584a to your computer and use it in GitHub Desktop.
Save komo91/5f2a10916b1dd162584a to your computer and use it in GitHub Desktop.
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