Skip to content

Instantly share code, notes, and snippets.

@xxtomoxy
Created January 11, 2015 15:49
Show Gist options
  • Save xxtomoxy/7124447ef86a467971b2 to your computer and use it in GitHub Desktop.
Save xxtomoxy/7124447ef86a467971b2 to your computer and use it in GitHub Desktop.
~3~
package work1;
import java.util.Random;
public class work1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
System.out.println("難易度を入力をしてください。");
System.out.println("1 10回以内に数字を当ててください。(a)");
System.out.println("2 20回以内に数字を当ててください。(b)");
System.out.println("3 10回以内に数字を当ててください。(c)");
Random rnd = new Random();
int ran = rnd.nextInt(50) + 1;
System.out.println(ran);
String line = System.console().readLine();
char c = line.charAt(0);
switch (c){
case '1':
System.out.println("10回以内に数字を当ててください。");
for (int i=0; i<10; i++) {
String line1 = System.console().readLine();
int n = Integer.parseInt(line1);
if (n>ran){
System.out.println("大きいです。");
}else if (n<ran){
System.out.println("小さいです。");
}else{
System.out.println("正解でsう。");
} break;
}
case '2':
System.out.println("20回以内に数字を当ててください。");
for (int i=0; i<20; i++) {
String line2 = System.console().readLine();
int m = Integer.parseInt(line2);
if (m>ran){
System.out.println("大きいです。");
}else if (m<ran){
System.out.println("小さいです。");
}else{
System.out.println("正解でsう。");
} break;
}
case '3':
System.out.println("30回以内に数字を当ててください。");
for (int i=0; i<30; i++) {
String line3 = System.console().readLine();
int l = Integer.parseInt(line3);
if (l>ran){
System.out.println("大きいです。");
}else if (l<ran){
System.out.println("小さいです。");
}else{
System.out.println("正解でsう。");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment