Skip to content

Instantly share code, notes, and snippets.

@AuroraNorthernQuarter
Created December 24, 2018 01:10
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 AuroraNorthernQuarter/66679e544805becb948fd07b4e576b5e to your computer and use it in GitHub Desktop.
Save AuroraNorthernQuarter/66679e544805becb948fd07b4e576b5e to your computer and use it in GitHub Desktop.
サンプルコード7-2-修正
package testprogramm;
import java.util.Scanner;
class oshiete {
public void livingthing() {
Scanner scan = new Scanner(System.in);
System.out.print("種別を入力してください: ");
String hensuunitsusite = scan.nextLine();
String syubetsu[] = new String[4];
String animal[] = new String[4];
String tousuu[] = new String[4];
syubetsu[0] = "動物";
syubetsu[1] = "動物";
syubetsu[2] = "動物";
syubetsu[3] = "植物";
animal[0] = "キリン";
animal[1] = "ライオン";
animal[2] = "ゴリラ";
animal[3] = "ひまわり";
tousuu[0] = "7頭";
tousuu[1] = "3頭";
tousuu[2] = "5頭";
tousuu[3] = "1本";
boolean found = false;
for (int i = 0; i < 4; i++) {
if (hensuunitsusite.equals(syubetsu[i])) {
System.out.println(animal[i]);
System.out.println(tousuu[i]);
found = true;
}
}
scan.close(); // ここで、Scanner の close をしておく
if (!found) {
System.out.println("種別がありません。再度入力してください。");
livingthing();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment