回答編集履歴
1
再帰呼出しを使わないコードを追加
test
CHANGED
@@ -83,3 +83,83 @@
|
|
83
83
|
}
|
84
84
|
|
85
85
|
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
**追記**
|
90
|
+
|
91
|
+
再帰呼出しを使わないと、
|
92
|
+
|
93
|
+
```Java
|
94
|
+
|
95
|
+
import java.util.Scanner;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
public class ShinIrekae {
|
100
|
+
|
101
|
+
final static String[] aiueo = {
|
102
|
+
|
103
|
+
"あぁかがさざただなはばぱまやゃらわ", "いぃきぎしじちぢにひびぴみりゐ",
|
104
|
+
|
105
|
+
"うぅくぐすずつづぬふぶぷむゆゅる", "えぇけげせぜてでねへべぺめれゑ",
|
106
|
+
|
107
|
+
"おぉこごそぞとどのほぼぽもよょろ"
|
108
|
+
|
109
|
+
};
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public static void main(String[] args) {
|
114
|
+
|
115
|
+
Scanner scn = new Scanner(System.in);
|
116
|
+
|
117
|
+
System.out.println("どのような文の子音を変えますか?");
|
118
|
+
|
119
|
+
String str = scn.nextLine();
|
120
|
+
|
121
|
+
int i, j, len = str.length(), dan[] = new int[len], pos[] = new int[len];
|
122
|
+
|
123
|
+
for (i = 0; i < str.length(); dan[i++] = j) {
|
124
|
+
|
125
|
+
char c = str.charAt(i);
|
126
|
+
|
127
|
+
if ((j = getDan(c)) < 0) System.out.println(c + "は、そのものです");
|
128
|
+
|
129
|
+
else System.out.println(c + "は、" + aiueo[j].charAt(0) + "段にあります");
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
do {
|
134
|
+
|
135
|
+
for (i = 0; i < len; i++)
|
136
|
+
|
137
|
+
if (dan[i] < 0) System.out.print(str.charAt(i));
|
138
|
+
|
139
|
+
else System.out.print(aiueo[dan[i]].charAt(pos[i]));
|
140
|
+
|
141
|
+
System.out.println();
|
142
|
+
|
143
|
+
for (i = len; --i >= 0; pos[i] = 0)
|
144
|
+
|
145
|
+
if ((j = dan[i]) >= 0 && ++pos[i] < aiueo[j].length()) break;
|
146
|
+
|
147
|
+
} while (i >= 0);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
static int getDan(char c) {
|
154
|
+
|
155
|
+
for (int i = 0; i < aiueo.length; i++)
|
156
|
+
|
157
|
+
if (aiueo[i].indexOf(c) >= 0) return i;
|
158
|
+
|
159
|
+
return -1;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|