This commit is contained in:
2026-10-27 16:48:43 +09:00
parent b6af93ba98
commit 6feb026bb4
42 changed files with 449 additions and 58 deletions

View File

@@ -1,44 +0,0 @@
public class Question06 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//設問1
for(int i = 0; i <= 99; i++) {
System.out.println(i);
}
//設問2
for(int i = 0; i <= 5; i++) {
System.out.print("■");
}
//設問3
for(int i = 0; i <= 100; i++) {
//偶数の判定
if(0 == (i%2))
System.out.println(i);
}
//設問4
for(int i = 1; i <= 49; 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);
}
for(int i =0; i <= 2; i++);
}
}

View File

@@ -0,0 +1,12 @@
public class Question06_01 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int i = 0; i <= 99; i++) {
System.out.println(i);
}
}
}

View File

@@ -0,0 +1,11 @@
public class Question06_02 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int i = 0; i <= 5; i++) {
System.out.print("■");
}
}
}

View File

@@ -0,0 +1,13 @@
public class Question06_03 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int i = 0; i <= 100; i++) {
//偶数の判定
if(0 == (i%2))
System.out.println(i);
}
}
}

View File

@@ -0,0 +1,26 @@
public class Question06_04 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int i = 1; i <= 49; 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);
}
for(int i =0; i <= 2; i++);
}
}

View File

@@ -0,0 +1,19 @@
import java.util.Random;
public class Question06_05 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタ
for(int i = 1; i <= 10; i++) {
Random random = new Random();
int num = random.nextInt(3);
if(num == 2) {
System.out.println();
}else {
System.out.println(num);
}
}
}
}

View File

@@ -0,0 +1,15 @@
public class Question06_06 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int n = 1; n <= 5; n ++) {
for(int i = 1; i <= 5; i ++) {
System.out.print("■");
}
System.out.println("");
}
}
}

View File

@@ -0,0 +1,17 @@
public class Question06_07 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
for(int i = 1; i <= 9; i++) {
for(int n = 1; n <= 9; n++) {
System.out.print(" " + i*n);
}
System.out.println();
}
}
}

View File

@@ -1,4 +1,4 @@
import java.util.Random;
public class Question07_05 { public class Question07_05 {
public static void main(String[] args) { public static void main(String[] args) {
@@ -6,11 +6,10 @@ public class Question07_05 {
String[] array = {"森", "山", "沼", "島", "平地"}; String[] array = {"森", "山", "沼", "島", "平地"};
for(int i = (int) Math.random(); i < array.length; i++) { Random random = new Random();
System.out.print(array[i]); int num = random.nextInt(5);
}
System.out.println(array[num]);
} }

View File

@@ -0,0 +1,14 @@
public class Question07_06 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
String[] array = {"森", "山", "沼", "島", "平地"};
for(int i = array.length-1; i >= 0; i --) {
System.out.print(array[i]);
}
}
}

View File

@@ -0,0 +1,12 @@
public class Question07_07 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
String[]day = {"月","火","水","木","金"};
String[]schedule = {"1時間目","2時間目","3時間目","4時間目","5時間目"};
System.out.println(day[day.ength]);
}
}

View File

@@ -0,0 +1,9 @@
public class Question07_08 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
}
}

View File

@@ -0,0 +1,9 @@
public class Question07_09 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
}
}

View File

@@ -0,0 +1,9 @@
public class Question07_10 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
}
}

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
Question09-Package/.gitignore vendored Normal file
View File

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

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question09-Package</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,10 @@
public class Question09_01 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
hello();
}
}

View File

@@ -0,0 +1,9 @@
package Question09_01;
public class Util {
public void hello() {
System.err.println("こんにちは");
}
}

View File

@@ -0,0 +1,9 @@
public class Question09_02 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
}
}

View File

@@ -0,0 +1,9 @@
public class Question09_03 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Random;
public class Car {
//フィールド
String color;
int gasoline;
//メソッド
public int run() {
this.gasoline = (gasoline -1);
if(gasoline >= 0) {
Random random = new Random();
int num = random.nextInt(16) + 1;
return num;
} else {
return -1;
}
}
}

View File

@@ -3,6 +3,17 @@ public class Question10_05 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
//インスタンス
Car car = new Car();
car.color = "赤";
car.gasoline = 50;
//runメソッドの実行
//car.run();
System.out.println(car.color +"色の車は" + car.run() +"進みました");
System.out.println(car.gasoline);
} }

View File

@@ -7,12 +7,13 @@ public class Atm {
//withdrawメソッドの生成 //withdrawメソッドの生成
public void withdraw(Wallet2 wallet,int money) { public void withdraw(Wallet2 wallet,int money) {
wallet.money = wallet.money + money;
if(credit < money) { if(this.credit < money) {
System.out.println("預金残高不足です。現金の引き出しに失敗しました。"); System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
} else { } else {
System.out.println("ATMの残り残高はx" + (credit - wallet.money) + "です"); this.credit = this.credit - money;
wallet.money = wallet.money + money;
System.out.println("ATMの残り残高は" + this.credit + "です");
} }
} }

View File

@@ -10,17 +10,19 @@ public class Question11_02 {
wallet.money = 10000; wallet.money = 10000;
//Atm 型の変数 atm を宣言し、Atm のインスタンスを代入 //Atm 型の変数 atm を宣言し、Atm のインスタンスを代入
Atm atm = new Atm(); Atm atm = new Atm();
//atm の withdraw メソッドを、第一引数に wallet、第二引数に 100000 を渡して呼び出す //atm の withdraw メソッドを、第一引数に wallet、第二引数に 100000 を渡して呼び出す
atm.withdraw(wallet,100000); atm.withdraw(wallet,100000);
//wallet の money フィールドの値を出力 //wallet の money フィールドの値を出力
System.out.println(wallet.money); System.out.println(wallet.money);
atm.withdraw(wallet,100000);
atm.withdraw(wallet,100000);
System.out.println(wallet.money); System.out.println(wallet.money);
} }

View File

@@ -0,0 +1,20 @@
public class Question11_04 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//Student2のインスタンス生成
Student2 deta = new Student2();
//生徒の名前(name フィールド)に 太郎 を設定
deta.name = "太郎";
Student2.group = "A";
Student2.teacher = "山田";
deta.studentProfile();
Student2.groupProfile();
}
}

View File

@@ -0,0 +1,17 @@
public class Student2 {
//Student2クラスで3つのフィールドを宣言する
String name;
static String group;
static String teacher;
//メソッドの定義
public void studentProfile() {
System.out.println(this.name +"は" + group +"教室の生徒です。");
}
public static void groupProfile() {
System.out.println(group +"教室の担任は" + teacher +"先生です。");
}
}

View File

@@ -2,4 +2,6 @@
public class Wallet2 { public class Wallet2 {
//フィールドの宣言 //フィールドの宣言
int money; int money;
} }

View File

@@ -1,4 +1,14 @@
//親クラス
public class Animal { public class Animal {
String name;
public void run() {
System.out.println(name + "は走りました。");
}
public void eat() {
System.out.println(name + "は食事をしました。");
}
} }

View File

@@ -0,0 +1,6 @@
//子クラス
public class Cat extends Animal {
public void Catprint () {
}
}

View File

@@ -0,0 +1,6 @@
//子クラス
public class Dog extends Animal {
public void Dogprint() {
System.out.println(name + "はドックフードを食べました。");
}
}

View File

@@ -3,6 +3,19 @@ public class Question13_01 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
//Catクラスのインスタンス生成
Cat cat = new Cat();
cat.name = "タマ";
Dog dog = new Dog();
dog.name = "ポチ";
cat.run();
cat.eat();
cat.Catprint();
dog.run();
dog.Dogprint();
} }

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
Question14-Interface/.gitignore vendored Normal file
View File

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

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question14-Interface</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,12 @@
public interface Book {
String bookname;
//メソッドの定義
void bookPrint();
String chapter(String chapter1,String chapter2,String chapter3,String chapter4,String chapter5);
}

View File

@@ -0,0 +1,9 @@
public class Question14_01 {
public static void main(String[] args) {
Book book = new Book();
book.bookname = "プログラミング基礎入門";
System.out.println(book.chapter());
}
}

View File

@@ -0,0 +1,14 @@
public class programmingBook implements Book {
String bookname;
public void bookPrint() {
System.out.println("プログラミング基礎入門");
}
public String chapter(String chapter1,String chapter2,String chapter3,String chapter4,String chapter5) {
return chapter1+"/"+ chapter2 +"/"+ chapter3 +"/"+ chapter4 +"/"+ chapter5;
}
}