-
-
Save mokomokohituji/77cf3454b98a4df1b028eddb753da9e0 to your computer and use it in GitHub Desktop.
いろはにほへとを生成
いろはにほへとを生成
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 com.company; | |
import java.util.Random; | |
public class Iroha { | |
public static void main(String[] args) { | |
// いろはにほへと をランダム出力します | |
Random random = new Random(); | |
String iroha = ""; | |
for (int i = 0; i <= 8; i++) { | |
int vac = random.nextInt(7); | |
String irohaCase = ""; | |
switch (vac) { | |
case 0: | |
irohaCase = "い"; | |
break; | |
case 1: | |
irohaCase = "ろ"; | |
break; | |
case 2: | |
irohaCase = "は"; | |
break; | |
case 3: | |
irohaCase = "に"; | |
break; | |
case 4: | |
irohaCase = "ほ"; | |
break; | |
case 5: | |
irohaCase = "へ"; | |
break; | |
case 6: | |
irohaCase = "と"; | |
break; | |
} | |
iroha += irohaCase; | |
} | |
System.out.println(iroha); | |
if(iroha.equals("いろはにほへと")){ | |
System.out.println("一致しました!おめでとう!"); | |
}else if(iroha.matches(".*" + "いろは" +"*.")||iroha.matches(".*" + "にほへと" +"*.")){ | |
System.out.println("おしい!もうすこしです!"); | |
} else { | |
System.out.println("残念ながら一致しませんでした"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment