1030自主学習

This commit is contained in:
2026-10-30 17:49:49 +09:00
parent d9529e2971
commit c0101fc96d
186 changed files with 2507 additions and 0 deletions

View 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
View File

@@ -0,0 +1 @@
/build/

23
Question04-while/.project Normal file
View 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>

View 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

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="21"/>
</faceted-project>

View File

@@ -0,0 +1,13 @@
public class Question4_1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 0;
while(num != 5) {
num = (int)(Math.random()*10);
System.out.println(num);
}
}
}

View File

@@ -0,0 +1,14 @@
public class Question4_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 2;
while(num < 1000) {
num *= 2;
System.out.println(num);
}
}
}

View File

@@ -0,0 +1,20 @@
public class Question4_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int num = 0;
while(true) {
num = (int)(Math.random()*10);
if(num !=5) {
System.out.println(num);
continue;
}else {
System.out.println(num);
break;
}
}
}
}

View File

@@ -0,0 +1,33 @@
import java.util.Scanner;
public class Question4_4 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
int map = 50;
int progress = 0;
int num = 0;
String str;
System.out.println("===== START =====");
while(progress <= map) {
System.out.println("Enterキーを押してください。さいころをふります。");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
System.out.println(str);
num = (int)(Math.random()*6) + 1;
System.out.println(num + "の目がでました。");
progress += num;
int remaining = map - progress;
if(progress < map) {
System.out.println("残りのマスは" + remaining + "マスです。");
}
}
System.out.println("===== GOAL =====");
}
}

View File

@@ -0,0 +1,53 @@
import java.util.Scanner;
public class Question4_5 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
boolean winFlag = false;
while(!winFlag) {
System.out.println("じゃんけんを行います。");
System.out.println("あなたの出す手を入力してください。");
System.out.println("0:グー、1:チョキ、2:パー");
Scanner sc = new Scanner(System.in);
int playerHand;
playerHand= sc.nextInt();
System.out.println(playerHand);
if(playerHand == 0) {
System.out.println("あなたはグーを出しました。");
}else if(playerHand == 1) {
System.out.println("あなたはチョキを出しました。");
}else {
System.out.println("あなたはパーを出しました。");
}
int num = (int)(Math.random()*3);
int npcHand = num;
if(npcHand ==0) {
System.out.println("相手はグーを出しました。");
}else if(npcHand ==1) {
System.out.println("相手はチョキを出しました。");
}else {
System.out.println("相手はパーを出しました。");
}
if(playerHand == 0 && npcHand ==1 || playerHand == 1 && npcHand ==2 || playerHand == 2 &&npcHand ==0) {
System.out.println("あなたの勝ちです。");
winFlag = true;
}else if(playerHand == npcHand) {
System.out.println("あいこです。");
System.out.println();
continue;
}else {
System.out.println("あなたの負けです。");
System.out.println();
continue;
}
}
}
}