Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
487005a537 | ||
|
|
6f29122307 | ||
|
|
ffce06d1ae |
6
Question01-StartProgram/.classpath
Normal file
6
Question01-StartProgram/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?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>
|
||||||
1
Question01-StartProgram/.gitignore
vendored
Normal file
1
Question01-StartProgram/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/bin/
|
||||||
17
Question01-StartProgram/.project
Normal file
17
Question01-StartProgram/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Question01-StartProgram</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>
|
||||||
@@ -8,7 +8,7 @@ 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.print("Hallo,word");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ public class PTra01_02 {
|
|||||||
//ここをコメントアウトする
|
//ここをコメントアウトする
|
||||||
|
|
||||||
// TODO 14行目 ~ 16行目を複数行コメントにしてコンパイルエラーが出ないようにしてください
|
// TODO 14行目 ~ 16行目を複数行コメントにしてコンパイルエラーが出ないようにしてください
|
||||||
// ここをコメントアウトする
|
/*ここをコメントアウトする
|
||||||
// ここをコメントアウトする
|
ここをコメントアウトする
|
||||||
// ここをコメントアウトする
|
ここをコメントアウトする*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class PTra01_03 {
|
|||||||
// TODO 文字列型の変数 str を宣言してください。
|
// TODO 文字列型の変数 str を宣言してください。
|
||||||
String str;
|
String str;
|
||||||
// TODO str に こんにちは を代入してください
|
// TODO str に こんにちは を代入してください
|
||||||
str = ("こんにちは");
|
str = "こんにちは";
|
||||||
// TODO str の値を出力してください
|
// TODO str の値を出力してください
|
||||||
System.out.println(str);
|
System.out.println(str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,28 @@ public class PTra01_09 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです)
|
// TODO 基本型8種類の変数を宣言します(変数名は自分できめてOKです)
|
||||||
int in;
|
byte a;
|
||||||
|
short b;
|
||||||
|
int c;
|
||||||
|
long d;
|
||||||
|
float e;
|
||||||
|
char f;
|
||||||
|
boolean g;
|
||||||
// TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです)
|
// TODO 宣言した変数に、値を代入してください(代入する値はなんでもOKです)
|
||||||
in = (123);
|
a = 1;
|
||||||
|
b = 10;
|
||||||
|
c = 100;
|
||||||
|
d = 1_000l;
|
||||||
|
e = 2f;
|
||||||
|
f = 'j';
|
||||||
|
g = true;
|
||||||
// TODO それぞれの変数の中身を出力してください
|
// TODO それぞれの変数の中身を出力してください
|
||||||
System.out.println(in);
|
System.out.println(a);
|
||||||
|
System.out.println(b);
|
||||||
|
System.out.println(c);
|
||||||
|
System.out.println(d);
|
||||||
|
System.out.println(e);
|
||||||
|
System.out.println(f);
|
||||||
|
System.out.println(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
Question02-Expressions/.classpath
Normal file
6
Question02-Expressions/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?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>
|
||||||
1
Question02-Expressions/.gitignore
vendored
Normal file
1
Question02-Expressions/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/bin/
|
||||||
17
Question02-Expressions/.project
Normal file
17
Question02-Expressions/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Question02-Expressions</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>
|
||||||
@@ -9,9 +9,8 @@ public class PTra02_06 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 以下のプログラムを実行すると割り算の結果の小数点以下が切り捨てられてしまいます。
|
// 以下のプログラムを実行すると割り算の結果の小数点以下が切り捨てられてしまいます。
|
||||||
// TODO 切り捨てられないように修正してください。
|
// TODO 切り捨てられないように修正してください。
|
||||||
double a = 9;
|
double a = 9.0 / 2.0;
|
||||||
double b = 2;
|
System.out.println(a);
|
||||||
System.out.println(a/b);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class PTra02_07 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 以下のソースコードからコンパイルエラーを取り除いてください
|
// TODO 以下のソースコードからコンパイルエラーを取り除いてください
|
||||||
// ※数値リテラル部分は編集しないでください
|
// ※数値リテラル部分は編集しないでください
|
||||||
double num = 1.0;
|
int num = (int)1.0;
|
||||||
|
|
||||||
// ※ 以下は編集しないでください。1と出力されていれば正解です
|
// ※ 以下は編集しないでください。1と出力されていれば正解です
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ public class PTra02_08 {
|
|||||||
// 所持金
|
// 所持金
|
||||||
int money = 1000;
|
int money = 1000;
|
||||||
// 商品価格(税抜)
|
// 商品価格(税抜)
|
||||||
double price = 580;
|
int price = 580;
|
||||||
// 消費税率
|
// 消費税率
|
||||||
double taxRate = 0.08;
|
double taxRate = 0.08;
|
||||||
|
|
||||||
// TODO 買い物した際の残金計算をします。
|
// TODO 買い物した際の残金計算をします。
|
||||||
|
int buy = money - price;
|
||||||
// TODO 所持金から価格を引いた値を、買い物後の所持金として再代入してください。
|
// TODO 所持金から価格を引いた値を、買い物後の所持金として再代入してください。
|
||||||
// ※消費税を考慮してください。税込み商品価格の端数は切り捨てとします。
|
// ※消費税を考慮してください。税込み商品価格の端数は切り捨てとします。
|
||||||
price = price *( 1 + taxRate);
|
money = (int) (buy * (1 +taxRate));
|
||||||
int pay = (int) price;
|
|
||||||
money = money - pay;
|
|
||||||
// 残金の表示部分です。編集しないでください
|
// 残金の表示部分です。編集しないでください
|
||||||
System.out.println("残金は" + money + "円です。");
|
System.out.println("残金は" + money + "円です。");
|
||||||
}
|
}
|
||||||
|
|||||||
6
Question03-if/.classpath
Normal file
6
Question03-if/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?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>
|
||||||
1
Question03-if/.gitignore
vendored
Normal file
1
Question03-if/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/bin/
|
||||||
17
Question03-if/.project
Normal file
17
Question03-if/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Question03-if</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>
|
||||||
@@ -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("不合格です");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,12 +22,13 @@ public class PTra03_04 {
|
|||||||
*/
|
*/
|
||||||
if (num >= 75) {
|
if (num >= 75) {
|
||||||
System.out.println("雨が降る確率が高いです");
|
System.out.println("雨が降る確率が高いです");
|
||||||
}
|
} else if (num < 74 && num> 30 ) {
|
||||||
else if (num >= 30) {
|
System.out.println("雨が降るかもしれないでしょう");
|
||||||
System.out.println("雨が降るかもしれないです");
|
} else {
|
||||||
}
|
System.out.println("雨はまず降らないでしょう");
|
||||||
else if (num < 30) {
|
|
||||||
System.out.println("雨は降らないでしょう");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
Question04-while/.classpath
Normal file
6
Question04-while/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?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>
|
||||||
1
Question04-while/.gitignore
vendored
Normal file
1
Question04-while/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/bin/
|
||||||
17
Question04-while/.project
Normal file
17
Question04-while/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?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>
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* PTra04_01.java
|
* PTra04_01.java
|
||||||
* 作成 Rhizome
|
* 作成 Rhizome
|
||||||
@@ -16,15 +15,13 @@ public class PTra04_01 {
|
|||||||
|
|
||||||
// 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。
|
// 以下のwhile文は0~9のランダムな値をコンソールに出力する処理を無限に繰り返します。
|
||||||
// TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。
|
// TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。
|
||||||
while (true) {
|
while(randomNumber != 5 ) {
|
||||||
// 0~9のランダムな値を生成
|
// 0~9のランダムな値を生成
|
||||||
randomNumber = random.nextInt(10);
|
randomNumber = random.nextInt(10);
|
||||||
// 生成した値をコンソールに出力
|
// 生成した値をコンソールに出力
|
||||||
System.out.println(randomNumber);
|
System.out.println(randomNumber);
|
||||||
if (randomNumber == 5) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ public class PTra04_02 {
|
|||||||
* ※ 繰り返しにはwhile文を用いてください
|
* ※ 繰り返しにはwhile文を用いてください
|
||||||
*/
|
*/
|
||||||
while( num <= 1000) {
|
while( num <= 1000) {
|
||||||
System.out.println(num);
|
|
||||||
num = num * 2;
|
num = num * 2;
|
||||||
}
|
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* PTra04_03.java
|
* PTra04_03.java
|
||||||
* 作成 Rhizome
|
* 作成 Rhizome
|
||||||
@@ -26,5 +25,9 @@ public class PTra04_03 {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class PTra04_04 {
|
|||||||
System.out.println("===== START =====");
|
System.out.println("===== START =====");
|
||||||
|
|
||||||
// TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。
|
// TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。
|
||||||
while (progress <= map) {
|
while(map > progress) {
|
||||||
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
|
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
|
||||||
System.out.println("Enterキーを押してください。さいころをふります。");
|
System.out.println("Enterキーを押してください。さいころをふります。");
|
||||||
scanner.nextLine();
|
scanner.nextLine();
|
||||||
@@ -35,16 +35,12 @@ public class PTra04_04 {
|
|||||||
|
|
||||||
// TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。
|
// TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。
|
||||||
// ※ #には変数diceの値が入ります。
|
// ※ #には変数diceの値が入ります。
|
||||||
System.out.println(dice + "の目が出ました");
|
System.out.println(dice + "の目が出ました。");
|
||||||
|
|
||||||
// TODO 変数progressに変数diceの値を加算してください。
|
// TODO 変数progressに変数diceの値を加算してください。
|
||||||
progress = progress + dice;
|
progress = progress + dice;
|
||||||
// TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。
|
// TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。
|
||||||
// ※ #には双六の残りのマス数が入ります。
|
// ※ #には双六の残りのマス数が入ります。
|
||||||
int rest = map - progress;
|
System.out.println("残りのマスは" + progress + "マスです。");
|
||||||
if (progress <= map) {
|
|
||||||
System.out.println("残りのマスは" + rest + "マスです");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("===== GOAL =====");
|
System.out.println("===== GOAL =====");
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ 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) {
|
if(playerHand == 0) {
|
||||||
System.out.println("あなたはグーを出しました" );
|
System.out.println("あなたはグーを出しました" );
|
||||||
}else if (playerHand == 1) {
|
}else if (playerHand == 1) {
|
||||||
System.out.println("あなたはチョキを出しました" );
|
System.out.println("あなたはチョキを出しました" );
|
||||||
} else if (playerHand == 2) {
|
}else {
|
||||||
System.out.println("あなたはパーを出しました" );
|
System.out.println("あなたはパーを出しました" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// 対戦相手の手をランダムに選択する。
|
// 対戦相手の手をランダムに選択する。
|
||||||
npcHand = random.nextInt(3);
|
npcHand = random.nextInt(3);
|
||||||
// TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等)
|
// TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等)
|
||||||
@@ -48,34 +48,28 @@ public class PTra04_05 {
|
|||||||
System.out.println("相手はグーを出しました" );
|
System.out.println("相手はグーを出しました" );
|
||||||
}else if (npcHand == 1) {
|
}else if (npcHand == 1) {
|
||||||
System.out.println("相手はチョキを出しました" );
|
System.out.println("相手はチョキを出しました" );
|
||||||
} else if (npcHand == 2) {
|
}else {
|
||||||
System.out.println("相手はパーを出しました" );
|
System.out.println("相手はパーを出しました" );
|
||||||
}
|
}
|
||||||
// TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
|
// TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
|
||||||
if (playerHand == 0 && npcHand == 1) {
|
if (playerHand == npcHand) {
|
||||||
System.out.println("あなたの勝ちです!");
|
System.out.println("あいこです" );
|
||||||
return;
|
}else if (playerHand == 0 && npcHand == 1) {
|
||||||
} else if (playerHand == 0 && npcHand == 0) {
|
System.out.println("あなたの負けです" );
|
||||||
System.out.println("あいこです。もう一度チャレンジ!");
|
|
||||||
} else if (playerHand == 0 && npcHand == 2) {
|
|
||||||
System.out.println("負けちゃいました…。もう一度チャレンジ!");
|
|
||||||
} else if (playerHand == 1 && npcHand == 1) {
|
|
||||||
System.out.println("あいこです。もう一度チャレンジ!");
|
|
||||||
} else if (playerHand == 1 && npcHand == 0) {
|
|
||||||
System.out.println("負けちゃいました…。もう一度チャレンジ!");
|
|
||||||
}else if (playerHand == 1 && npcHand == 2) {
|
}else if (playerHand == 1 && npcHand == 2) {
|
||||||
System.out.println("あなたの勝ちです!");
|
System.out.println("あなたの負けです" );
|
||||||
return;
|
|
||||||
}else if (playerHand == 2 && npcHand == 0) {
|
}else if (playerHand == 2 && npcHand == 0) {
|
||||||
System.out.println("あなたの勝ちです!");
|
System.out.println("あなたの負けです" );
|
||||||
return;
|
}
|
||||||
} else if (playerHand == 2 && npcHand == 1) {
|
else {
|
||||||
System.out.println("負けちゃいました…。もう一度チャレンジ!");
|
{
|
||||||
} else if (playerHand == 2 && npcHand == 2) {
|
System.out.println("あなたの勝ちです、プログラムを終了します" );
|
||||||
System.out.println("あいこです。もう一度チャレンジ!");
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// 次のじゃんけんの前に改行しておく
|
// 次のじゃんけんの前に改行しておく
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
6
Question05-switch/.classpath
Normal file
6
Question05-switch/.classpath
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?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>
|
||||||
17
Question05-switch/.project
Normal file
17
Question05-switch/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?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>
|
||||||
@@ -11,6 +11,7 @@ public class PTra05_01 {
|
|||||||
// ランダムな数値をnumに代入します。範囲は 0 ~ 5 です。
|
// ランダムな数値をnumに代入します。範囲は 0 ~ 5 です。
|
||||||
int num = new java.util.Random().nextInt(6);
|
int num = new java.util.Random().nextInt(6);
|
||||||
|
|
||||||
|
|
||||||
// TODO 以下の条件に沿ったプログラムを記述してください
|
// TODO 以下の条件に沿ったプログラムを記述してください
|
||||||
// ※ switch文を使用してプログラムを記述してください
|
// ※ switch文を使用してプログラムを記述してください
|
||||||
/*
|
/*
|
||||||
@@ -22,25 +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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,25 +29,6 @@ public class PTra05_02 {
|
|||||||
* 変数choiceの値が % の場合 -> num1 を num2 で 割った余り を出力
|
* 変数choiceの値が % の場合 -> num1 を num2 で 割った余り を出力
|
||||||
* 変数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("計算に失敗しました");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,24 +42,6 @@ public class PTra05_03 {
|
|||||||
|
|
||||||
// TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。
|
// TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。
|
||||||
// ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。
|
// ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。
|
||||||
switch (judgement) {
|
|
||||||
case "H":
|
|
||||||
if (dealerCard <= myCard) {
|
|
||||||
System.out.println("あなたの勝ちです");
|
|
||||||
} else {
|
|
||||||
System.out.println("あなたの負けです");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "L":
|
|
||||||
if (dealerCard >= myCard) {
|
|
||||||
System.out.println("あなたの勝ちです");
|
|
||||||
} else {
|
|
||||||
System.out.println("あなたの負けです");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("不正な数値が入力されました");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user