Created
March 17, 2015 09:45
-
-
Save takoeight0821/2e518354e2b7b817a865 to your computer and use it in GitHub Desktop.
Java で 数当てゲーム
This file contains 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.io.*; | |
public class Main { | |
static int small = 1; | |
static int big = 100; | |
private static int guessMyNumber() { | |
return (small + big) / 2; | |
} | |
private static int smaller() { | |
big = guessMyNumber() - 1; | |
return guessMyNumber(); | |
} | |
private static int bigger() { | |
small = guessMyNumber() + 1; | |
return guessMyNumber(); | |
} | |
public static void main(String[] args) throws IOException { | |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
boolean isFinish = false; | |
String mes; | |
while (!isFinish) { | |
mes = in.readLine(); | |
switch (mes) { | |
case "smaller": | |
System.out.println(smaller()); | |
break; | |
case "bigger": | |
System.out.println(bigger()); | |
break; | |
case "yes": | |
System.out.println("Yeah! Thank you playing!"); | |
isFinish = true; | |
break; | |
default: | |
System.out.println(guessMyNumber()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment