mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 22:57:48 +08:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -10,7 +10,7 @@ public class iteration {
|
||||
/* for ループ */
|
||||
static int forLoop(int n) {
|
||||
int res = 0;
|
||||
// 1, 2, ..., n-1, n の合計をループ計算
|
||||
// 1, 2, ..., n-1, n を順に加算する
|
||||
for (int i = 1; i <= n; i++) {
|
||||
res += i;
|
||||
}
|
||||
@@ -20,35 +20,35 @@ public class iteration {
|
||||
/* while ループ */
|
||||
static int whileLoop(int n) {
|
||||
int res = 0;
|
||||
int i = 1; // 条件変数を初期化
|
||||
// 1, 2, ..., n-1, n の合計をループ計算
|
||||
int i = 1; // 条件変数を初期化する
|
||||
// 1, 2, ..., n-1, n を順に加算する
|
||||
while (i <= n) {
|
||||
res += i;
|
||||
i++; // 条件変数を更新
|
||||
i++; // 条件変数を更新する
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* while ループ(2つの更新) */
|
||||
/* while ループ(2回更新) */
|
||||
static int whileLoopII(int n) {
|
||||
int res = 0;
|
||||
int i = 1; // 条件変数を初期化
|
||||
// 1, 4, 10, ... の合計をループ計算
|
||||
int i = 1; // 条件変数を初期化する
|
||||
// 1, 4, 10, ... を順に加算する
|
||||
while (i <= n) {
|
||||
res += i;
|
||||
// 条件変数を更新
|
||||
// 条件変数を更新する
|
||||
i++;
|
||||
i *= 2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* 2重 for ループ */
|
||||
/* 二重 for ループ */
|
||||
static String nestedForLoop(int n) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
// ループ i = 1, 2, ..., n-1, n
|
||||
// i = 1, 2, ..., n-1, n とループする
|
||||
for (int i = 1; i <= n; i++) {
|
||||
// ループ j = 1, 2, ..., n-1, n
|
||||
// j = 1, 2, ..., n-1, n とループする
|
||||
for (int j = 1; j <= n; j++) {
|
||||
res.append("(" + i + ", " + j + "), ");
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class iteration {
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
/* ドライバーコード */
|
||||
/* Driver Code */
|
||||
public static void main(String[] args) {
|
||||
int n = 5;
|
||||
int res;
|
||||
@@ -68,9 +68,9 @@ public class iteration {
|
||||
System.out.println("\nwhile ループの合計結果 res = " + res);
|
||||
|
||||
res = whileLoopII(n);
|
||||
System.out.println("\nwhile ループ(2つの更新)の合計結果 res = " + res);
|
||||
System.out.println("\nwhile ループ(2 回更新)の合計結果 res = " + res);
|
||||
|
||||
String resStr = nestedForLoop(n);
|
||||
System.out.println("\n2重 for ループ走査の結果 = " + resStr);
|
||||
System.out.println("\n二重 for ループの走査結果 " + resStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user