10 Commits

Author SHA1 Message Date
25eafd2abe Question04-03 2026-09-15 13:52:18 +09:00
9072735cdc Question04-02 2026-09-14 14:24:05 +09:00
2259a37dac Question04 01 2026-09-11 16:55:17 +09:00
471943fb37 Question03 01-04 2026-09-11 16:24:14 +09:00
db136573ab Question02 08 2026-09-11 15:59:23 +09:00
76612e75f8 Question02 06-07 2026-09-11 15:30:19 +09:00
9bd5a8e422 Question02 01-05 2026-09-11 14:59:27 +09:00
151b793f09 Question09 2026-09-11 14:30:34 +09:00
ad3f339f73 Question06-08 2026-09-11 14:10:57 +09:00
deb89b6c5d Question01-05 2026-09-11 13:22:43 +09:00
37 changed files with 119 additions and 313 deletions

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Question01-StartProgram/src"/>
<classpathentry kind="src" path="Question02-Expressions/src"/>
<classpathentry kind="src" path="Question03-if/src"/>
<classpathentry kind="src" path="Question04-while/src"/>
<classpathentry kind="src" path="Question05-switch/src"/>
<classpathentry kind="src" path="Question06-for/src"/>
<classpathentry kind="src" path="Question07-Array/src"/>
<classpathentry kind="src" path="Question08-Method/src"/>
<classpathentry kind="src" path="Question09-Package/src"/>
<classpathentry kind="src" path="Question10-InstanceAndClass/src"/>
<classpathentry kind="src" path="Question11-ConstructorAndStatic/src"/>
<classpathentry kind="src" path="Question12-Encapsulation/src"/>
<classpathentry kind="src" path="Question13-Extends/src"/>
<classpathentry kind="src" path="Question14-Interface/src"/>
<classpathentry kind="src" path="Question15-Polymorphism/src"/>
<classpathentry kind="src" path="Question16-JavaStandardClass/src"/>
<classpathentry kind="src" path="Question17-Exception/src"/>
<classpathentry kind="src" path="Question18-StringOperation/src"/>
<classpathentry kind="src" path="Question19-Collection/src"/>
<classpathentry kind="src" path="Question20-InstanceBasicOperation/src"/>
<classpathentry kind="src" path="Question21-DifferentTypesClass/src"/>
<classpathentry kind="src" path="Question22-FunctionAndLambda/src"/>
<classpathentry kind="src" path="Question23-NonStandardLibrary/src"/>
<classpathentry kind="src" path="Question24-VariousFileFormats/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored
View File

@@ -24,4 +24,3 @@
hs_err_pid* hs_err_pid*
replay_pid* replay_pid*
/bin/

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java-question</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -8,7 +8,6 @@ public class PTra01_01 {
public static void main(String[] args) { public static void main(String[] args) {
//TODO Hello,world と出力してください //TODO Hello,world と出力してください
System.out.println("Hello,world"); System.out.println("Hello, World!");
} }
} }

View File

@@ -15,6 +15,5 @@ public class PTra01_03 {
// TODO str の値を出力してください // TODO str の値を出力してください
System.out.println(str); System.out.println(str);
} }
} }

View File

@@ -8,10 +8,10 @@ public class PTra01_04 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 数値型の変数 number を 10 で初期化してください。 // TODO 数値型の変数 number を 10 で初期化してください。
//int[] number = new int[10];
int number = 10; int number = 10;
// TODO number の値を出力してください // TODO number の値を出力してください
System.out.println(number); System.out.println(number);
} }
} }

View File

@@ -8,7 +8,7 @@ public class PTra01_05 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO char型の変数 ch を A で初期化してください。 // TODO char型の変数 ch を A で初期化してください。
char ch = 'A'; String ch = "A";
// TODO ch の値を出力してください // TODO ch の値を出力してください
System.out.println(ch); System.out.println(ch);

View File

@@ -8,10 +8,9 @@ public class PTra01_06 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO boolean型の変数 bo を true で初期化してください。 // TODO boolean型の変数 bo を true で初期化してください。
boolean bo = true; String bo = "true";
// TODO bo の値を出力してください // TODO bo の値を出力してください
System.out.println(bo); System.out.println(bo);
} }
} }

View File

@@ -8,10 +8,9 @@ public class PTra01_07 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO long型の変数 lo を 1000000000000 で初期化してください。 // TODO long型の変数 lo を 1000000000000 で初期化してください。
long lo = 1000000000000L; long LargeNumber = 1000000000000L;
// TODO lo の値を出力してください // TODO lo の値を出力してください
System.out.println(lo); System.out.println(LargeNumber);
} }
} }

View File

@@ -8,10 +8,9 @@ public class PTra01_08 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO float型の変数 fl を 3.14 で初期化してください。 // TODO float型の変数 fl を 3.14 で初期化してください。
float fl = 3.14F; float Number = 3.14f;
// TODO fl の値を出力してください // TODO fl の値を出力してください
System.out.println(fl); System.out.println(Number);
} }
} }

View File

@@ -8,38 +8,36 @@ public class PTra01_09 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです) // TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです)
String name;
byte bNum; int Birthday;
short sNum; //宣言?
int iNum; float Number;
long lNum; long LargeNumber;
float fMin; double Number2;
double dMin; char Character;
char ch1; short SmallNumber;
boolean boo;
// TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです) // TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです)
bNum = 127; name = "Sara";
sNum = 30000; Birthday = 7;
iNum = 10000; boolean isAdult = true;
lNum = 50000L; boolean isChild = false;
fMin = 0.01F; Number = 3.1415926535f;
dMin = 0.001; Number2 = 8.979323846;
ch1 = 'N'; LargeNumber = 1234567890L;
boo = true; Character = 'a';
SmallNumber = 123;
// TODO それぞれの変数の中身を出力してください // TODO それぞれの変数の中身を出力してください
System.out.println(bNum); System.out.println(name);
System.out.println(sNum); System.out.println(Birthday);
System.out.println(iNum); System.out.println("成人です:" + isAdult);
System.out.println(lNum); System.out.println("未成年です:" + isChild);
System.out.println(fMin); System.out.println(Number);
System.out.println(dMin); System.out.println(Number2);
System.out.println(ch1); System.out.println(LargeNumber);
System.out.println(boo); System.out.println(Character);
System.out.println(SmallNumber);
} }
} }

View File

@@ -14,19 +14,19 @@ public class PTra02_01 {
int rem; int rem;
// TODO 6+2を計算して結果を変数sumに代入してください // TODO 6+2を計算して結果を変数sumに代入してください
sum = 6 + 2; sum = 6+2;
// TODO 6-2を計算して結果を変数diffに代入してください // TODO 6-2を計算して結果を変数diffに代入してください
diff = 6 - 2; diff = 6-2;
// TODO 6×2を計算して結果を変数mulchに代入してください // TODO 6×2を計算して結果を変数mulchに代入してください
mulch = 6 * 2; mulch = 6*2;
// TODO 6÷2を計算して結果を変数divに代入してください // TODO 6÷2を計算して結果を変数divに代入してください
div = 6 / 2; div = 6/2;
// TODO 17÷5の余りを計算して変数remに代入してください // TODO 17÷5の余りを計算して変数remに代入してください
rem = 17 % 5; rem = 17%5;
// 各変数の表示(編集しないでください) // 各変数の表示(編集しないでください)
// ※ 8, 4, 12, 3, 2の順で表示されれば正解です // ※ 8, 4, 12, 3, 2の順で表示されれば正解です

View File

@@ -11,8 +11,8 @@ public class PTra02_02 {
String lastName = "山田"; String lastName = "山田";
// TODO 苗字と名前をつなげて山田太郎と出力してください。 // TODO 苗字と名前をつなげて山田太郎と出力してください。
// ※ System.out.printlnを使うのは1回だけです。
System.out.println(lastName + firstName); System.out.println(lastName + firstName);
// ※ System.out.printlnを使うのは1回だけです。
} }

View File

@@ -9,7 +9,12 @@ public class PTra02_04 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 以下のソースコードからコンパイルエラーを取り除いてください // TODO 以下のソースコードからコンパイルエラーを取り除いてください
// ※数値リテラル部分は編集しないでください // ※数値リテラル部分は編集しないでください
double sum = 10 + 3.14; // int sum = 10 + 3.14;
int value = 10;
double value2 = 3.14;
double sum = value + value2;
// ※以下は編集しないでください。13.14と出力されていれば正解です // ※以下は編集しないでください。13.14と出力されていれば正解です
System.out.println(sum); System.out.println(sum);

View File

@@ -19,7 +19,7 @@ public class PTra02_05 {
int diff = 5; int diff = 5;
System.out.println("山田さんは" + age + "歳です。"); System.out.println("山田さんは" + age + "歳です。");
System.out.println(diff + "年後には" + (age + diff) + "歳になります。"); System.out.println(diff + "年後には" + ( age + diff )+ "歳になります。");
} }
} }

View File

@@ -9,8 +9,13 @@ public class PTra02_06 {
public static void main(String[] args) { public static void main(String[] args) {
// 以下のプログラムを実行すると割り算の結果の小数点以下が切り捨てられてしまいます。 // 以下のプログラムを実行すると割り算の結果の小数点以下が切り捨てられてしまいます。
// TODO 切り捨てられないように修正してください。 // TODO 切り捨てられないように修正してください。
//System.out.println(9/2);
System.out.println((double)9/2); // double value = 9/2;
// System.out.println(value);
double value = 9/2;
System.out.println(String.format("%.2f", value));
} }

View File

@@ -8,7 +8,10 @@ public class PTra02_07 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 以下のソースコードからコンパイルエラーを取り除いてください // TODO 以下のソースコードからコンパイルエラーを取り除いてください
// ※数値リテラル部分は編集しないでください // ※数値リテラル部分は編集しないでください
int num = (int)1.0; double value = 1.0;
//int value = num.intValue();
;
int num = (int) value;
// ※ 以下は編集しないでください。1と出力されていれば正解です // ※ 以下は編集しないでください。1と出力されていれば正解です
System.out.println(num); System.out.println(num);

View File

@@ -17,10 +17,15 @@ public class PTra02_08 {
// TODO 買い物した際の残金計算をします。 // TODO 買い物した際の残金計算をします。
// TODO 所持金から価格を引いた値を、買い物後の所持金として再代入してください。 // TODO 所持金から価格を引いた値を、買い物後の所持金として再代入してください。
// ※消費税を考慮してください。税込み商品価格の端数は切り捨てとします。 // ※消費税を考慮してください。税込み商品価格の端数は切り捨てとします。
money = money - (price + (int)(price * taxRate));
// 残金の表示部分です。編集しないでください //public static void remainingMoney() {
System.out.println("残金は" + money + "円です。"); int result = (int) (price * (1 + taxRate)); // +1 が必要
money = money - result;
// return money;
// }
// 残金の表示部分です。編集しないでください
System.out.println("残金は"+money+"円です。");
} }
} }

View File

@@ -8,6 +8,7 @@ public class PTra03_01 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO int型の変数numを宣言し、100で初期化してください // TODO int型の変数numを宣言し、100で初期化してください
int num = 100; int num = 100;
// TODO「変数numが100である」という条件式を追加してください // TODO「変数numが100である」という条件式を追加してください

View File

@@ -7,15 +7,17 @@
public class PTra03_02 { public class PTra03_02 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO int型の変数numを宣言し、65で初期化してください // TODO int型の変数numを宣言し、65で初期化してください
int num = 65; int num = 65;
// TODO 変数numの値が65以上の場合は「合格です」と出力し、それ以外であれば「不合格です」を出力してください // TODO 変数numの値が65以上の場合は「合格です」と出力し、それ以外であれば「不合格です」を出力してください
// ※ 合格です と表示されれば正解
if(num>=65) { if (num >=65) {
System.out.println("合格です"); System.out.println("合格です");
}else { } else {
System.out.println("不合格です"); System.out.println("不合格です");
} }
// ※ 合格です と表示されれば正解
} }
} }

View File

@@ -9,8 +9,9 @@ public class PTra03_03 {
int num = 10; int num = 10;
// TODO numが 2で割り切れる かつ 5で割り切れるという条件式を記述してください // TODO numが 2で割り切れる かつ 5で割り切れるという条件式を記述してください
if (num % 2 == 0 && num % 5 == 0) {
System.out.println(num + "は2でも5でも割り切れます。"); if (num % 2 == 0 && num % 5 ==0) {
System.out.println(num + "は2でも5でも割り切れます。");
} }
} }
} }

View File

@@ -20,14 +20,18 @@ public class PTra03_04 {
* *
* ※ 変数numの値が 0より小さい または 100より大きい場合は「不正な値が入力されました」と出力してください。 * ※ 変数numの値が 0より小さい または 100より大きい場合は「不正な値が入力されました」と出力してください。
*/ */
if ((num < 0) || (100 < num)) {
System.out.println("不正な値が入力されました"); if (100 > num && num >= 75) {
} else if (75 <= num) {
System.out.println("雨が降る確率が高いです"); System.out.println("雨が降る確率が高いです");
} else if (30 <= num) {
} else if (74 >= num && num >= 30) {
System.out.println("雨が降るかもしれないです"); System.out.println("雨が降るかもしれないです");
} else {
} else if (num < 0 || 100 <num) {
System.out.println("不正な値が入力されました");
} else{
System.out.println("雨はまず降らないでしょう"); System.out.println("雨はまず降らないでしょう");
} }
} }
} }

View File

@@ -1,3 +1,4 @@
/* /*
* PTra04_01.java * PTra04_01.java
* 作成 Rhizome * 作成 Rhizome
@@ -15,14 +16,16 @@ public class PTra04_01 {
// 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。 // 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。
// TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。 // TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。
while(randomNumber!=5) { while (true) {
// 0~9のランダムな値を生成 // 0~9のランダムな値を生成
randomNumber = random.nextInt(10); randomNumber = random.nextInt(10);
if (randomNumber == 5) {
System.out.println("5が出力されたため処理を終了します");
break;
}
// 生成した値をコンソールに出力 // 生成した値をコンソールに出力
System.out.println(randomNumber); System.out.println(randomNumber);
} }
} }

View File

@@ -14,11 +14,13 @@ public class PTra04_02 {
* numが1000を超えるまで繰り返しを行ってください。 * numが1000を超えるまで繰り返しを行ってください。
* 繰り返しの中でnumを2倍した数値をnumに代入してください。 * 繰り返しの中でnumを2倍した数値をnumに代入してください。
* ※ 繰り返しにはwhile文を用いてください * ※ 繰り返しにはwhile文を用いてください
*
*/ */
while(num<1000) { while (num <= 1000) {
num=num*2; //num = num * 2;
num *= 2;
System.out.println(num); System.out.println(num);
} }

View File

@@ -1,3 +1,4 @@
/* /*
* PTra04_03.java * PTra04_03.java
* 作成 Rhizome * 作成 Rhizome
@@ -16,17 +17,17 @@ public class PTra04_03 {
// 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。 // 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。
// TODO 5が出力されたら繰り返しを止めるようにしてください。 // TODO 5が出力されたら繰り返しを止めるようにしてください。
// ※ while文の条件は変更せずにbreak文を使ってください。 // ※ while文の条件は変更せずにbreak文を使ってください。
while(true) { while (true) {
// 0~9のランダムな値を生成 // 0~9のランダムな値を生成
randomNumber = random.nextInt(10); randomNumber = random.nextInt(10);
// 生成した値をコンソールに出力 // 生成した値をコンソールに出力
System.out.println(randomNumber); System.out.println(randomNumber);
if(randomNumber==5) { if (randomNumber == 5) {
break; break;
} }
} }
System.out.println("処理が終了しました");
} }
} }

View File

@@ -1,4 +1,3 @@
/* /*
* PTra04_04.java * PTra04_04.java
* 作成 Rhizome * 作成 Rhizome
@@ -19,15 +18,13 @@ public class PTra04_04 {
Random random = new Random(); Random random = new Random();
// TODO 双六の総コマ数としてint型の変数mapを宣言し、50を代入してください。 // TODO 双六の総コマ数としてint型の変数mapを宣言し、50を代入してください。
int map=50;
// TODO 現在までの進んだコマ数としてint型の変数progressを宣言し、0を代入してください。 // TODO 現在までの進んだコマ数としてint型の変数progressを宣言し、0を代入してください。
int progress=0;
System.out.println("===== START ====="); System.out.println("===== START =====");
// TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。 // TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。
while(progress<map) { while() {
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。 // 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
System.out.println("Enterキーを押してください。さいころをふります。"); System.out.println("Enterキーを押してください。さいころをふります。");
scanner.nextLine(); scanner.nextLine();
@@ -37,16 +34,12 @@ public class PTra04_04 {
// TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。 // TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。
// ※ #には変数diceの値が入ります。 // ※ #には変数diceの値が入ります。
System.out.println(dice+"の目が出ました");
// TODO 変数progressに変数diceの値を加算してください。 // TODO 変数progressに変数diceの値を加算してください。
progress=progress+dice;
// TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。 // TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。
// ※ #には双六の残りのマス数が入ります。 // ※ #には双六の残りのマス数が入ります。
System.out.println("残りのマスは"+(map-progress)+"マスです");
} }
System.out.println("===== GOAL ====="); System.out.println("===== GOAL =====");

View File

@@ -32,68 +32,13 @@ public class PTra04_05 {
System.out.println("0:グー, 1:チョキ, 2:パー"); System.out.println("0:グー, 1:チョキ, 2:パー");
playerHand = Integer.parseInt(scanner.nextLine()); playerHand = Integer.parseInt(scanner.nextLine());
// TODO 選ばれた手を出力してください(0なら"あなたはグーを出しました"等) // TODO 選ばれた手を出力してください(0なら"あなたはグーを出しました"等)
if(playerHand==0) {
System.out.println("あなたはグーを出しました");
}
if(playerHand==1) {
System.out.println("あなたはチョキを出しました");
}
if(playerHand==2) {
System.out.println("あなたはパーを出しました");
}
// 対戦相手の手をランダムに選択する。 // 対戦相手の手をランダムに選択する。
npcHand = random.nextInt(3); npcHand = random.nextInt(3);
// TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等) // TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等)
if(npcHand==0) {
System.out.println("相手はグーを出しました");
}
if(npcHand==1) {
System.out.println("相手はチョキを出しました");
}
if(npcHand==2) {
System.out.println("相手はパーを出しました");
}
// TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。 // TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
if(playerHand==0) {
if(npcHand==0) {
System.out.println("あいこです");
continue;
}else if(npcHand==1) {
System.out.println("勝ちです");
break;
}else{
System.out.println("負けです");
continue;
}
}
if(playerHand==1) {
if(npcHand==1) {
System.out.println("あいこです");
continue;
}else if(npcHand==2) {
System.out.println("勝ちです");
break;
}else {
System.out.println("負けです");
continue;
}
}if(playerHand==2) {
if(npcHand==2) {
System.out.println("あいこです");
continue;
}else if(npcHand==0) {
System.out.println("勝ちです");
break;
}else {
System.out.println("負けです");
continue;
}
}
// 次のじゃんけんの前に改行しておく // 次のじゃんけんの前に改行しておく
System.out.println(); System.out.println();

View File

@@ -23,27 +23,5 @@ public class PTra05_01 {
* 変数numの値が 4 の場合 -> あなたの運勢は「末吉」です * 変数numの値が 4 の場合 -> あなたの運勢は「末吉」です
* 変数numの値が 5 の場合 -> あなたの運勢は「凶」です * 変数numの値が 5 の場合 -> あなたの運勢は「凶」です
*/ */
switch(num) {
case 0:
System.out.println("あなたの運勢は「大吉」です");
break;
case 1:
System.out.println("あなたの運勢は「吉」です");
break;
case 2:
System.out.println("あなたの運勢は「中吉」です");
break;
case 3:
System.out.println("あなたの運勢は「小吉」です");
break;
case 4:
System.out.println("あなたの運勢は「末吉」です");
break;
case 5:
System.out.println("あなたの運勢は「凶」です");
break;
}
} }
} }

View File

@@ -30,28 +30,6 @@ public class PTra05_02 {
* 変数choiceの値が 上記以外 の場合 -> 計算に失敗しました を出力 * 変数choiceの値が 上記以外 の場合 -> 計算に失敗しました を出力
*/ */
switch(choice) {
case "+":
System.out.println(num1+num2);
break;
case "-":
System.out.println(num1-num2);
break;
case "*":
System.out.println(num1*num2);
break;
case "/":
System.out.println(num1/num2);
break;
case "%":
System.out.println(num1%num2);
break;
default:
System.out.println("計算に失敗しました");
}
}
} }
}

View File

@@ -42,27 +42,6 @@ public class PTra05_03 {
// TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。 // TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。
// ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。 // ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。
switch(judgement) {
case "H":
if(myCard>dealerCard) {
System.out.println("あなたの勝ちです");
break;
}
if(myCard<dealerCard) {
System.out.println("あなたの負けです");
break;
}
case"L":
if(myCard<dealerCard) {
System.out.println("あなたの勝ちです");
break;
}
if(myCard>dealerCard) {
System.out.println("あなたの負けです");
break;
}
}
} }
} }

View File

@@ -7,10 +7,6 @@
public class PTra06_01 { public class PTra06_01 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO for文を使って0から99までの整数を順にコンソールに出力してください。 // TODO for文を使って0から99までの整数を順にコンソールに出力してください。
for (int i = 0; i < 100; i++) {
System.out.println(i);
}
} }
} }

View File

@@ -10,10 +10,6 @@ public class PTra06_02 {
/* /*
* ■■■■■ * ■■■■■
*/ */
for(int i=0;i<5;i++) {
System.out.print("■");
}
} }

View File

@@ -11,12 +11,6 @@ public class PTra06_03 {
for (int i = 0; i <= 100; i++) { for (int i = 0; i <= 100; i++) {
// TODO iが偶数の時だけ、iの値を出力してください // TODO iが偶数の時だけ、iの値を出力してください
if(i%2==0) {
System.out.println(i);
}else {
continue;
}
} }
} }

View File

@@ -13,17 +13,7 @@ public class PTra06_04 {
* ③ iが3でも5でも割り切れる場合はfizzbuzzと出力する * ③ iが3でも5でも割り切れる場合はfizzbuzzと出力する
* ④ 上記のいずれにも当てはまらない場合はiの値をそのまま出力する * ④ 上記のいずれにも当てはまらない場合はiの値をそのまま出力する
*/ */
for (int i = 1; i < 50; i++) { for(int i = 1;i < 50;i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("fizzbuzz");
} else if (i % 3 == 0) {
System.out.println("fizz");
} else if (i % 5 == 0) {
System.out.println("buzz");
} else {
System.out.println(i);
}
} }

View File

@@ -1,4 +1,3 @@
/* /*
* PTra06_05.java * PTra06_05.java
* 作成 Rhizome * 作成 Rhizome
@@ -17,13 +16,11 @@ public class PTra06_05 {
// 以下のfor文は0~2のランダムな値を10回出力します。 // 以下のfor文は0~2のランダムな値を10回出力します。
// TODO 値が2の場合は出力しないようにしてください。 // TODO 値が2の場合は出力しないようにしてください。
// ※ continueを用いてください。 // ※ continueを用いてください。
for (int i = 0; i < 10; i++) { for(int i = 0;i < 10;i++) {
randomNumber = random.nextInt(3); randomNumber = random.nextInt(3);
if (randomNumber == 2) {
continue;
} else { System.out.println(randomNumber);
System.out.println(randomNumber);
}
} }
} }
} }

View File

@@ -15,14 +15,6 @@ public class PTra06_06 {
* ■■■■■ * ■■■■■
*/ */
for(int i=1;i<=25;i++) {
if(i%5==0) {
System.out.println("■");
}else {
System.out.print("■");
}
}
} }
} }

View File

@@ -19,16 +19,6 @@ public class PTra06_07 {
* 8 16 24 32 40 48 56 64 72 * 8 16 24 32 40 48 56 64 72
* 9 18 27 36 45 54 63 72 81 * 9 18 27 36 45 54 63 72 81
*/ */
int num=1;
for(int i=1;num<10;i++) {
if(i%9==0) {
System.out.println(num*i);
i=1;
num=num+1;
}else {
System.out.print(num*i);
}
}
} }