20261027
This commit is contained in:
@@ -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++);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
12
Question06-for/src/main/java/Question06_01.java
Normal file
12
Question06-for/src/main/java/Question06_01.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Question06-for/src/main/java/Question06_02.java
Normal file
11
Question06-for/src/main/java/Question06_02.java
Normal 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("■");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
13
Question06-for/src/main/java/Question06_03.java
Normal file
13
Question06-for/src/main/java/Question06_03.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
Question06-for/src/main/java/Question06_04.java
Normal file
26
Question06-for/src/main/java/Question06_04.java
Normal 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++);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
19
Question06-for/src/main/java/Question06_05.java
Normal file
19
Question06-for/src/main/java/Question06_05.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
15
Question06-for/src/main/java/Question06_06.java
Normal file
15
Question06-for/src/main/java/Question06_06.java
Normal 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("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
17
Question06-for/src/main/java/Question06_07.java
Normal file
17
Question06-for/src/main/java/Question06_07.java
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
import java.util.Random;
|
||||
public class Question07_05 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -6,11 +6,10 @@ public class Question07_05 {
|
||||
String[] array = {"森", "山", "沼", "島", "平地"};
|
||||
|
||||
|
||||
for(int i = (int) Math.random(); i < array.length; i++) {
|
||||
System.out.print(array[i]);
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int num = random.nextInt(5);
|
||||
|
||||
System.out.println(array[num]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
14
Question07-Array/src/main/java/Question07_06.java
Normal file
14
Question07-Array/src/main/java/Question07_06.java
Normal 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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
12
Question07-Array/src/main/java/Question07_07.java
Normal file
12
Question07-Array/src/main/java/Question07_07.java
Normal 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]);
|
||||
}
|
||||
|
||||
}
|
||||
9
Question07-Array/src/main/java/Question07_08.java
Normal file
9
Question07-Array/src/main/java/Question07_08.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question07_08 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
9
Question07-Array/src/main/java/Question07_09.java
Normal file
9
Question07-Array/src/main/java/Question07_09.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question07_09 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
9
Question07-Array/src/main/java/Question07_10.java
Normal file
9
Question07-Array/src/main/java/Question07_10.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question07_10 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
6
Question09-Package/.classpath
Normal file
6
Question09-Package/.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
Question09-Package/.gitignore
vendored
Normal file
1
Question09-Package/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build/
|
||||
23
Question09-Package/.project
Normal file
23
Question09-Package/.project
Normal 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>
|
||||
9
Question09-Package/.settings/org.eclipse.jdt.core.prefs
Normal file
9
Question09-Package/.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>
|
||||
10
Question09-Package/src/main/java/Question09_01.java
Normal file
10
Question09-Package/src/main/java/Question09_01.java
Normal file
@@ -0,0 +1,10 @@
|
||||
public class Question09_01 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
hello();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
9
Question09-Package/src/main/java/Question09_01/Util.java
Normal file
9
Question09-Package/src/main/java/Question09_01/Util.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Question09_01;
|
||||
|
||||
public class Util {
|
||||
|
||||
public void hello() {
|
||||
System.err.println("こんにちは");
|
||||
}
|
||||
|
||||
}
|
||||
9
Question09-Package/src/main/java/Question09_02.java
Normal file
9
Question09-Package/src/main/java/Question09_02.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question09_02 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
9
Question09-Package/src/main/java/Question09_03.java
Normal file
9
Question09-Package/src/main/java/Question09_03.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question09_03 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
24
Question10-InstanceAndClass/src/main/java/Car.java
Normal file
24
Question10-InstanceAndClass/src/main/java/Car.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,17 @@ public class Question10_05 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ public class Atm {
|
||||
//withdrawメソッドの生成
|
||||
public void withdraw(Wallet2 wallet,int money) {
|
||||
|
||||
wallet.money = wallet.money + money;
|
||||
|
||||
if(credit < money) {
|
||||
if(this.credit < money) {
|
||||
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
||||
} 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 + "です");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,17 +10,19 @@ public class Question11_02 {
|
||||
wallet.money = 10000;
|
||||
|
||||
|
||||
|
||||
//Atm 型の変数 atm を宣言し、Atm のインスタンスを代入
|
||||
Atm atm = new Atm();
|
||||
|
||||
|
||||
//atm の withdraw メソッドを、第一引数に wallet、第二引数に 100000 を渡して呼び出す
|
||||
atm.withdraw(wallet,100000);
|
||||
|
||||
//wallet の money フィールドの値を出力
|
||||
System.out.println(wallet.money);
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
|
||||
atm.withdraw(wallet,100000);
|
||||
System.out.println(wallet.money);
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
Question11-ConstructorAndStatic/src/main/java/Student2.java
Normal file
17
Question11-ConstructorAndStatic/src/main/java/Student2.java
Normal 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 +"先生です。");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,4 +2,6 @@
|
||||
public class Wallet2 {
|
||||
//フィールドの宣言
|
||||
int money;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
|
||||
//親クラス
|
||||
public class Animal {
|
||||
String name;
|
||||
|
||||
public void run() {
|
||||
System.out.println(name + "は走りました。");
|
||||
}
|
||||
|
||||
public void eat() {
|
||||
System.out.println(name + "は食事をしました。");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
6
Question13-Extends/src/main/java/Cat.java
Normal file
6
Question13-Extends/src/main/java/Cat.java
Normal file
@@ -0,0 +1,6 @@
|
||||
//子クラス
|
||||
public class Cat extends Animal {
|
||||
public void Catprint () {
|
||||
|
||||
}
|
||||
}
|
||||
6
Question13-Extends/src/main/java/Dog.java
Normal file
6
Question13-Extends/src/main/java/Dog.java
Normal file
@@ -0,0 +1,6 @@
|
||||
//子クラス
|
||||
public class Dog extends Animal {
|
||||
public void Dogprint() {
|
||||
System.out.println(name + "はドックフードを食べました。");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,19 @@ public class Question13_01 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
//Catクラスのインスタンス生成
|
||||
Cat cat = new Cat();
|
||||
cat.name = "タマ";
|
||||
|
||||
Dog dog = new Dog();
|
||||
dog.name = "ポチ";
|
||||
|
||||
cat.run();
|
||||
cat.eat();
|
||||
cat.Catprint();
|
||||
|
||||
dog.run();
|
||||
dog.Dogprint();
|
||||
|
||||
}
|
||||
|
||||
|
||||
6
Question14-Interface/.classpath
Normal file
6
Question14-Interface/.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
Question14-Interface/.gitignore
vendored
Normal file
1
Question14-Interface/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build/
|
||||
23
Question14-Interface/.project
Normal file
23
Question14-Interface/.project
Normal 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>
|
||||
@@ -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>
|
||||
12
Question14-Interface/src/main/java/Book.java
Normal file
12
Question14-Interface/src/main/java/Book.java
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
public interface Book {
|
||||
|
||||
String bookname;
|
||||
|
||||
|
||||
//メソッドの定義
|
||||
void bookPrint();
|
||||
|
||||
String chapter(String chapter1,String chapter2,String chapter3,String chapter4,String chapter5);
|
||||
|
||||
}
|
||||
9
Question14-Interface/src/main/java/Question14_01.java
Normal file
9
Question14-Interface/src/main/java/Question14_01.java
Normal 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());
|
||||
}
|
||||
}
|
||||
14
Question14-Interface/src/main/java/programmingBook.java
Normal file
14
Question14-Interface/src/main/java/programmingBook.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user