-
-
Save AuroraNorthernQuarter/1d97d3bb5e5ad9061105b2b8fa49180f to your computer and use it in GitHub Desktop.
サンプルコード7-2
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
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本"; | |
for (int i = 0; i < 4; i++) { | |
if (hensuunitsusite.equals(syubetsu[i])) { | |
System.out.println(animal[i]); | |
System.out.println(tousuu[i]); | |
} | |
else { | |
System.out.println("種別がありません。再度入力してください。"); | |
} | |
} | |
scan.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment