10/30自習
This commit is contained in:
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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
1
Question04-while/.gitignore
vendored
Normal file
1
Question04-while/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build/
|
||||
23
Question04-while/.project
Normal file
23
Question04-while/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
9
Question04-while/.settings/org.eclipse.jdt.core.prefs
Normal file
9
Question04-while/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="21"/>
|
||||
</faceted-project>
|
||||
16
Question04-while/src/main/java/Question04_1.java
Normal file
16
Question04-while/src/main/java/Question04_1.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class Question04_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
Random rand = new Random();
|
||||
int num = rand.nextInt(10);
|
||||
|
||||
while (num != 5) {
|
||||
System.out.println(num);
|
||||
num = rand.nextInt(10);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
Question04-while/src/main/java/Question04_2.java
Normal file
16
Question04-while/src/main/java/Question04_2.java
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
public class Question04_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int num = 2;
|
||||
|
||||
while(num < 1000) {
|
||||
num = num * 2;
|
||||
|
||||
}
|
||||
System.out.println(num);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
20
Question04-while/src/main/java/Question04_3.java
Normal file
20
Question04-while/src/main/java/Question04_3.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class Question04_3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
while (true) {
|
||||
int num = rand.nextInt(10);
|
||||
if (num == 5) {
|
||||
break;
|
||||
}
|
||||
System.out.println(num);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
34
Question04-while/src/main/java/Question04_4.java
Normal file
34
Question04-while/src/main/java/Question04_4.java
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
public class Question04_4 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int map = 50, progress = 0;
|
||||
|
||||
System.out.println("===== START =====");
|
||||
|
||||
while (map >= progress) {
|
||||
|
||||
System.out.println("Enterキーを押してください。さいころをふります。" + "\n");
|
||||
|
||||
double rand = Math.random() * 6 + 1;
|
||||
int num = (int) rand;
|
||||
|
||||
System.out.println(num + "の目が出ました。");
|
||||
progress += num;
|
||||
|
||||
if (map >= progress) {
|
||||
|
||||
System.out.println("残りのマスは" + (map - progress) + "マスです。");
|
||||
|
||||
} else {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("===== GOAL =====");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
51
Question04-while/src/main/java/Question04_5.java
Normal file
51
Question04-while/src/main/java/Question04_5.java
Normal file
@@ -0,0 +1,51 @@
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class Question04_5 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
System.out.println("じゃんけんを行います");
|
||||
System.out.println("あなたの出す手を入力してください");
|
||||
System.out.println("0:グー, 1:チョキ, 2:パー");
|
||||
String[] hands = {"グー", "チョキ", "パー"};
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int playerHand = sc.nextInt();
|
||||
Random rand = new Random();
|
||||
int npcHand = rand.nextInt(3);
|
||||
|
||||
|
||||
|
||||
|
||||
boolean winFlag = true;
|
||||
|
||||
while(true) {
|
||||
System.out.println("あなたは" + hands[playerHand] + "を出しました");
|
||||
System.out.println("相手は" + hands[npcHand] + "を出しました");
|
||||
|
||||
|
||||
if(npcHand == playerHand) {
|
||||
winFlag = false;
|
||||
System.out.println("引き分け");
|
||||
} else if ((npcHand == 0 && playerHand == 1) || (npcHand == 1 && playerHand == 2) || (npcHand == 2 && playerHand == 0)) {
|
||||
System.out.println("負け");
|
||||
break;
|
||||
} else if((npcHand == 1 && playerHand == 0) || (npcHand == 2 && playerHand == 1) || (npcHand == 0 && playerHand == 2)) {
|
||||
System.out.println("勝ち");
|
||||
break;
|
||||
|
||||
} while (winFlag) {
|
||||
} if((npcHand == 0 && playerHand == 1) || (npcHand == 1 && playerHand == 2) || (npcHand == 2 && playerHand == 0)) {
|
||||
System.out.println("負け");
|
||||
break;
|
||||
} else if ((npcHand == 1 && playerHand == 0) || (npcHand == 2 && playerHand == 1) || (npcHand == 0 && playerHand == 2)) {
|
||||
System.out.println("勝ち");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user