3 Commits

Author SHA1 Message Date
4a1e817855 Question3です 2026-09-11 16:55:42 +09:00
85a626ef91 Question2です 2026-09-11 16:19:51 +09:00
81d17fd20a Question01です 2026-09-11 15:03:28 +09:00
25 changed files with 91 additions and 168 deletions

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.print("Hallo,word"); System.out.println("Hello,world");
} }
} }

View File

@@ -11,9 +11,9 @@ public class PTra01_02 {
//ここをコメントアウトする //ここをコメントアウトする
// TODO 14行目 ~ 16行目を複数行コメントにしてコンパイルエラーが出ないようにしてください // TODO 14行目 ~ 16行目を複数行コメントにしてコンパイルエラーが出ないようにしてください
/*ここをコメントアウトする // ここをコメントアウトする
ここをコメントアウトする // ここをコメントアウトする
ここをコメントアウトする*/ // ここをコメントアウトする
} }
} }

View File

@@ -8,10 +8,10 @@ public class PTra01_03 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 文字列型の変数 str を宣言してください。 // TODO 文字列型の変数 str を宣言してください。
String str; String str = "こんにちは";
// TODO str に こんにちは を代入してください // TODO str に こんにちは を代入してください
str = "こんにちは";
// TODO str の値を出力してください
System.out.println(str); System.out.println(str);
// TODO str の値を出力してください
} }
} }

View File

@@ -8,7 +8,7 @@ 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 fl = 3.14f;
// TODO fl の値を出力してください // TODO fl の値を出力してください
System.out.println(fl); System.out.println(fl);
} }

View File

@@ -8,28 +8,28 @@ public class PTra01_09 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです) // TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです)
byte a; String st = "Hello";
short b; int in = 2;
int c; char ch = 'a';
long d; boolean boo = true;
float e; double dou = 1.0e308;
char f; long lo = 2222222222222L;
boolean g; float fo = 3.12f;
byte byt = 124;
short sh = 42;
// TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです) // TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです)
a = 1;
b = 10;
c = 100;
d = 1_000l;
e = 2f;
f = 'j';
g = true;
// TODO それぞれの変数の中身を出力してください // TODO それぞれの変数の中身を出力してください
System.out.println(a); System.out.println(st);
System.out.println(b); System.out.println(in);
System.out.println(c); System.out.println(ch);
System.out.println(d); System.out.println(boo);
System.out.println(e); System.out.println(dou);
System.out.println(f); System.out.println(lo);
System.out.println(g); System.out.println(fo);
System.out.println(byt);
System.out.println(sh);;
} }
} }

View File

@@ -7,22 +7,22 @@
public class PTra02_01 { public class PTra02_01 {
public static void main(String[] args) { public static void main(String[] args) {
int sum; int sum = 6+2;
int diff; int diff = 6-2;
int mulch; int mulch = 6*2;
int div; int div = 6/2;
int rem; int rem = 17%5 ;
// TODO 6+2を計算して結果を変数sumに代入してください // TODO 6+2を計算して結果を変数sumに代入してください
sum = 6 + 2;
// TODO 6-2を計算して結果を変数diffに代入してください // TODO 6-2を計算して結果を変数diffに代入してください
diff = 6 -2;
// TODO 6×2を計算して結果を変数mulchに代入してください // TODO 6×2を計算して結果を変数mulchに代入してください
mulch = 6 * 2;
// TODO 6÷2を計算して結果を変数divに代入してください // TODO 6÷2を計算して結果を変数divに代入してください
div = 6 / 2;
// TODO 17÷5の余りを計算して変数remに代入してください // TODO 17÷5の余りを計算して変数remに代入してください
rem = 17 % 5;
// 各変数の表示(編集しないでください) // 各変数の表示(編集しないでください)
// ※ 8, 4, 12, 3, 2の順で表示されれば正解です // ※ 8, 4, 12, 3, 2の順で表示されれば正解です
System.out.println("変数sum :" + sum); System.out.println("変数sum :" + sum);

View File

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

View File

@@ -10,7 +10,7 @@ public class PTra02_03 {
int num = 10; int num = 10;
// TODO numに5を足した値をnumに代入してください // TODO numに5を足した値をnumに代入してください
num = num + 5; num = 10 + 5;
// numの値を出力します(編集しないでください)。 // numの値を出力します(編集しないでください)。
// ※ 15と出力されれば正解です。 // ※ 15と出力されれば正解です。
System.out.println(num); System.out.println(num);

View File

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

View File

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

View File

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

View File

@@ -12,8 +12,8 @@ public class PTra03_02 {
// ※ 合格です と表示されれば正解 // ※ 合格です と表示されれば正解
if (num >= 65) { if (num >= 65) {
System.out.println("合格です"); System.out.println("合格です");
}else }else {
System.out.println("不合格です"); System.out.println("不合格です");
} }
} }
}

View File

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

View File

@@ -4,6 +4,7 @@
*------------------------------------------------------------ *------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved. * Copyright(c) Rhizome Inc. All Rights Reserved.
*/ */
public class PTra03_04 { public class PTra03_04 {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("降水確率を入力してください。(数字のみ)"); System.out.println("降水確率を入力してください。(数字のみ)");
@@ -20,15 +21,16 @@ public class PTra03_04 {
* *
* ※ 変数numの値が 0より小さい または 100より大きい場合は「不正な値が入力されました」と出力してください。 * ※ 変数numの値が 0より小さい または 100より大きい場合は「不正な値が入力されました」と出力してください。
*/ */
if (num >= 75) { if (num >= 75 && num <= 100) {
System.out.println("雨が降る確率が高いです"); System.out.println("雨が降る確率が高いです");
} else if (num < 74 && num> 30 ) { }else if (num >= 30 && num < 75) {
System.out.println("雨が降るかもしれないでしょう"); System.out.println("雨が降るかもしれないです");
} else { }
else if (num < 30){
System.out.println("雨はまず降らないでしょう"); System.out.println("雨はまず降らないでしょう");
}
else if (num < 0 || num >100 ) {
System.out.println("不正な値が入力されました");
} }
} }
} }

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1 +0,0 @@
/bin/

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question04-while</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

@@ -15,13 +15,12 @@ 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);
// 生成した値をコンソールに出力 // 生成した値をコンソールに出力
System.out.println(randomNumber); System.out.println(randomNumber);
} }
}
} }
}

View File

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

View File

@@ -21,13 +21,7 @@ public class PTra04_03 {
randomNumber = random.nextInt(10); randomNumber = random.nextInt(10);
// 生成した値をコンソールに出力 // 生成した値をコンソールに出力
System.out.println(randomNumber); System.out.println(randomNumber);
if (randomNumber == 5) {
break;
}
}
} }
} }
}

View File

@@ -1,4 +1,3 @@
/* /*
* PTra04_04.java * PTra04_04.java
* 作成 Rhizome * 作成 Rhizome
@@ -19,13 +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(map > progress) { while() {
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。 // 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
System.out.println("Enterキーを押してください。さいころをふります。"); System.out.println("Enterキーを押してください。さいころをふります。");
scanner.nextLine(); scanner.nextLine();
@@ -35,12 +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("残りのマスは" + progress + "マスです。");
} }
System.out.println("===== GOAL ====="); System.out.println("===== GOAL =====");

View File

@@ -1,4 +1,3 @@
/* /*
* PTra04_05.java * PTra04_05.java
* 作成 Rhizome * 作成 Rhizome
@@ -33,43 +32,16 @@ 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なら"あなたはグーを出しました"等)
//System.out.println("あなたは" + playerHand + "を出しました" );
if(playerHand == 0) {
System.out.println("あなたはグーを出しました" );
}else if (playerHand == 1) {
System.out.println("あなたはチョキを出しました" );
}else {
System.out.println("あなたはパーを出しました" );
}
// 対戦相手の手をランダムに選択する。 // 対戦相手の手をランダムに選択する。
npcHand = random.nextInt(3); npcHand = random.nextInt(3);
// TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等) // TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等)
if(npcHand == 0) {
System.out.println("相手はグーを出しました" );
}else if (npcHand == 1) {
System.out.println("相手はチョキを出しました" );
}else {
System.out.println("相手はパーを出しました" );
}
// TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
if (playerHand == npcHand) {
System.out.println("あいこです" );
}else if (playerHand == 0 && npcHand == 1) {
System.out.println("あなたの負けです" );
}else if (playerHand == 1 && npcHand == 2) {
System.out.println("あなたの負けです" );
}else if (playerHand == 2 && npcHand == 0) {
System.out.println("あなたの負けです" );
}
else {
{
System.out.println("あなたの勝ちです、プログラムを終了します" );
System.exit(0);
}
}
} // TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
// 次のじゃんけんの前に改行しておく // 次のじゃんけんの前に改行しておく
System.out.println(); System.out.println();
} }
} }
}

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question05-switch</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>