Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e804fff63 | |||
| 60e3eeb77f | |||
| aa48e98dae | |||
| 55aebdc8fa | |||
| f1e00a5534 | |||
| 3036f2c3c3 | |||
| 548d5421b8 | |||
| 8c3324660c | |||
| 8153c32000 | |||
| 7bf8f299ba | |||
| 62be6a9ae8 | |||
| f9779651c7 | |||
| aa782d40b0 | |||
| a11098f1cb | |||
| e5ec987d32 |
@@ -5,7 +5,19 @@
|
|||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<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>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
11
Question01-StartProgram/src/main/java/Question1_1.java
Normal file
11
Question01-StartProgram/src/main/java/Question1_1.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
public class Question1_1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
System.out.println("`Hello,world`");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
Question01-StartProgram/src/main/java/Question1_2.java
Normal file
16
Question01-StartProgram/src/main/java/Question1_2.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
public class Question1_2 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//1行だけを無効化する方法
|
||||||
|
/*
|
||||||
|
複数行をまとめて無効化する方法
|
||||||
|
*/
|
||||||
|
|
||||||
|
System.out.println("テスト");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
Question01-StartProgram/src/main/java/Question1_3.java
Normal file
16
Question01-StartProgram/src/main/java/Question1_3.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
public class Question1_3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数strを宣言して代入する
|
||||||
|
String str;
|
||||||
|
str = "こんにちは";
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Question01-StartProgram/src/main/java/Question1_4.java
Normal file
15
Question01-StartProgram/src/main/java/Question1_4.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
public class Question1_4 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数numberを値10で初期化する
|
||||||
|
int number = 10;
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(number);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Question01-StartProgram/src/main/java/Question1_5.java
Normal file
15
Question01-StartProgram/src/main/java/Question1_5.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
public class Question1_5 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数chを値Aで初期化する
|
||||||
|
char ch = 'A';
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(ch);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Question01-StartProgram/src/main/java/Question1_6.java
Normal file
15
Question01-StartProgram/src/main/java/Question1_6.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
public class Question1_6 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数boを値trueで初期化する
|
||||||
|
boolean bo = true;
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(bo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Question01-StartProgram/src/main/java/Question1_7.java
Normal file
15
Question01-StartProgram/src/main/java/Question1_7.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
public class Question1_7 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数loを値1000000000000で初期化する
|
||||||
|
long lo = 1000000000000L;
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(lo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Question01-StartProgram/src/main/java/Question1_8.java
Normal file
15
Question01-StartProgram/src/main/java/Question1_8.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
public class Question1_8 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数flを値3.14で初期化する
|
||||||
|
float fl = 3.14F;
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(fl);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
Question01-StartProgram/src/main/java/Question1_9.java
Normal file
42
Question01-StartProgram/src/main/java/Question1_9.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
public class Question1_9 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
//変数宣言
|
||||||
|
boolean bl; // true or false
|
||||||
|
char ch; // 16ビットUnicode文字 u0000-uFFFF
|
||||||
|
byte by; // 8ビット整数 -128~127 (符号ビット+2^7)
|
||||||
|
short sh; // 16ビット整数 -32,768~32,767 (符号ビット+2^15)
|
||||||
|
int num; // 32ビット整数 -2,147,483,648~2,147,483,647 (符号ビット+2^31)
|
||||||
|
long lo; // 64ビット整数 -9,223,372,036,854,775,808~9,223,372,036,854,775,807 (符号ビット+2^63)
|
||||||
|
float fl; // 32ビット単精度浮動小数点数
|
||||||
|
double db; // 64ビット倍精度浮動小数点数
|
||||||
|
String str; // 文字列を扱うクラス
|
||||||
|
|
||||||
|
//代入
|
||||||
|
bl = true;
|
||||||
|
ch = 'A';
|
||||||
|
by = 100;
|
||||||
|
sh = 10000;
|
||||||
|
num = 1000000000;
|
||||||
|
lo = 1000000000000000000L;
|
||||||
|
fl = 3.1415926F;
|
||||||
|
db = 1e2;
|
||||||
|
str = "DONE";
|
||||||
|
|
||||||
|
//出力
|
||||||
|
System.out.println(bl);
|
||||||
|
System.out.println(ch);
|
||||||
|
System.out.println(by);
|
||||||
|
System.out.println(sh);
|
||||||
|
System.out.println(num);
|
||||||
|
System.out.println(lo);
|
||||||
|
System.out.println(fl);
|
||||||
|
System.out.println(db);
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,20 +3,21 @@ public class Question2_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int sum = (6 + 2);
|
|
||||||
System.out.println(sum);
|
|
||||||
|
|
||||||
int diff = (6 - 2);
|
int sum, diff, mulch, div, rem;
|
||||||
System.out.println(diff);
|
|
||||||
|
|
||||||
int mulch = (6 * 2);
|
sum = 6 + 2;
|
||||||
System.out.println(mulch);
|
diff = 6 - 2;
|
||||||
|
mulch = 6 * 2;
|
||||||
|
div = 6 / 2;
|
||||||
|
rem = 17 % 5;
|
||||||
|
|
||||||
int div = (6 / 2);
|
System.out.println("変数sum:" + sum);
|
||||||
System.out.println(div);
|
System.out.println("変数diff:" + diff);
|
||||||
|
System.out.println("変数mulch:" + mulch);
|
||||||
int rem = (17 % 5);
|
System.out.println("変数div:" + div);
|
||||||
System.out.println(rem);
|
System.out.println("変数rem:" + rem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ public class Question2_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String lastName = "山田";
|
|
||||||
String firstName = "太郎";
|
|
||||||
|
|
||||||
System.out.println(lastName + firstName);
|
String lastName = "太郎";
|
||||||
|
String firstName = "山田";
|
||||||
|
|
||||||
|
System.out.println(firstName+lastName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,13 @@ public class Question2_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
int num = 10;
|
int num = 10;
|
||||||
num += 5;
|
|
||||||
|
num = num + 5;
|
||||||
|
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,16 @@ public class Question2_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
float sum;
|
|
||||||
int num = 10;
|
|
||||||
float fl= 3.14f;
|
|
||||||
|
|
||||||
sum = num + fl;
|
// error
|
||||||
|
// int sum;
|
||||||
|
// sum = 10 + 3.14;
|
||||||
|
|
||||||
|
double sum;
|
||||||
|
sum = 10 + 3.14;
|
||||||
|
|
||||||
System.out.println(sum);
|
System.out.println(sum);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ public class Question2_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
int age = 20;
|
int age = 20;
|
||||||
int diff = 5;
|
int diff = 5;
|
||||||
|
|
||||||
System.out.println("山田さんは" + age + "歳です。");
|
System.out.println("山田さんは"+age+"歳です。");
|
||||||
System.out.println(diff + "年後には" + (age + diff) + "歳になります。");
|
System.out.println(diff+"年後には"+(age+diff)+"歳になります。");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ public class Question2_6 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
float sum = 9f / 2f;
|
|
||||||
System.out.println(sum);
|
int numerator = 9;
|
||||||
|
int denominator = 2;
|
||||||
|
|
||||||
|
System.out.println( (float)numerator/(float)denominator );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,16 @@ public class Question2_7 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num = (int)1.0;
|
|
||||||
|
int num;
|
||||||
|
|
||||||
|
// error
|
||||||
|
// num = 1.0;
|
||||||
|
|
||||||
|
num = (int)1.0;
|
||||||
|
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ public class Question2_8 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
int money = 1000;
|
int money = 1000;
|
||||||
int price = 580;
|
int price = 580;
|
||||||
float taxRate = 0.08f;
|
float taxRate = 0.08F;
|
||||||
|
|
||||||
float tax = (int) (price * taxRate);
|
money = money - (int)( price*(1.0+taxRate) );
|
||||||
|
|
||||||
float total = price + tax;
|
System.out.println("残金は"+money+"円です。");
|
||||||
money -= total;
|
|
||||||
|
|
||||||
System.out.println("残金は" + money + "円です。");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ public class Question3_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
//設問1
|
|
||||||
int num;
|
int num = 100;
|
||||||
num = 100;
|
|
||||||
if(num == 100) {
|
if ( num == 100 ) {
|
||||||
System.out.println("条件に合致しました");
|
System.out.println("条件に合致しました");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ public class Question3_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num;
|
|
||||||
num = 65;
|
int num = 65;
|
||||||
if(num >= 65) {
|
|
||||||
|
if ( num >= 65 ) {
|
||||||
System.out.println("合格です");
|
System.out.println("合格です");
|
||||||
}else if(num < 65) {
|
} else {
|
||||||
System.out.println("不合格です");
|
System.out.println("不合格です");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ public class Question3_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num;
|
|
||||||
num = 10;
|
int num = 10;
|
||||||
if (num % 2 == 0 && num % 5 == 0) {
|
|
||||||
System.out.println(num + "は2でも5でも割り切れます。");
|
if ( (num % 2 == 0 ) && ( num % 5 == 0 ) ) {
|
||||||
|
System.out.println(num+"は"+2+"でも"+5+"でも割り切れます");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,23 @@ public class Question3_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
System.out.println("降水確率を入力してください。(数字のみ)");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
int num = sc.nextInt();
|
|
||||||
|
|
||||||
if(num < 0 || num >100){
|
System.out.println("降水確率を入力してください。(数字のみ)");
|
||||||
|
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int num = Integer.parseInt(sc.nextLine());
|
||||||
|
sc.close();
|
||||||
|
|
||||||
|
if ( (num<0) || (num>100) ) {
|
||||||
System.out.println("不正な値が入力されました");
|
System.out.println("不正な値が入力されました");
|
||||||
}else if(num >= 75) {
|
} else if ( num >= 75 ) {
|
||||||
System.out.println("雨が降る確率が高いです");
|
System.out.println("雨が降る確率が高いです");
|
||||||
}else if(num >= 30 && num <75) {
|
} else if ( (num<75) && (num>=30) ) {
|
||||||
System.out.println("雨が降るかもしれないです");
|
System.out.println("雨が降るかもしれないです");
|
||||||
}else if (num < 30) {
|
} else {
|
||||||
System.out.println("雨はまず降らないでしょう");
|
System.out.println("雨はまず降らないでしょう");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ public class Question4_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num = 0;
|
|
||||||
|
|
||||||
while(num != 5) {
|
int num = 0;
|
||||||
num = (int)(Math.random()*10);
|
while ( num!=5 ) {
|
||||||
|
num = (int)( Math.random()*10 );
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ public class Question4_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num = 2;
|
|
||||||
|
|
||||||
while(num < 1000) {
|
int num = 2;
|
||||||
num *= 2;
|
while ( num<=1000 ) {
|
||||||
System.out.println(num);
|
num = num*2;
|
||||||
}
|
}
|
||||||
|
System.out.println(num);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,16 @@ public class Question4_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int num = 0;
|
|
||||||
|
|
||||||
while(true) {
|
int num = 0;
|
||||||
num = (int)(Math.random()*10);
|
while ( true ) {
|
||||||
if(num !=5) {
|
num = (int)( Math.random()*10 );
|
||||||
System.out.println(num);
|
System.out.println(num);
|
||||||
continue;
|
if ( num==5 ) {
|
||||||
}else {
|
|
||||||
System.out.println(num);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,30 +4,29 @@ public class Question4_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
int map = 50;
|
int map = 50;
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
int num = 0;
|
|
||||||
String str;
|
|
||||||
|
|
||||||
System.out.println("===== START =====");
|
System.out.println("===== START =====");
|
||||||
|
|
||||||
while(progress <= map) {
|
while ( true ) {
|
||||||
|
|
||||||
System.out.println("Enterキーを押してください。さいころをふります。");
|
System.out.println("Enterキーを押してください。さいころをふります。");
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
str = sc.nextLine();
|
String str = sc.nextLine();
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
num = (int)(Math.random()*6) + 1;
|
int num = (int)( Math.random()*6+1 );
|
||||||
System.out.println(num + "の目がでました。");
|
System.out.println(num+"の目が出ました。");
|
||||||
|
progress = progress + num;
|
||||||
|
|
||||||
|
if ( map-progress<=0 ) { break; }
|
||||||
|
System.out.println("残りのマスは"+(map-progress)+"マスです。");
|
||||||
|
|
||||||
progress += num;
|
|
||||||
int remaining = map - progress;
|
|
||||||
if(progress < map) {
|
|
||||||
System.out.println("残りのマスは" + remaining + "マスです。");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("===== GOAL =====");
|
System.out.println("===== GOAL =====");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,50 +4,64 @@ public class Question4_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
boolean winFlag = false;
|
|
||||||
|
|
||||||
while(!winFlag) {
|
boolean winflag = false;
|
||||||
System.out.println("じゃんけんを行います。");
|
|
||||||
System.out.println("あなたの出す手を入力してください。");
|
|
||||||
System.out.println("0:グー、1:チョキ、2:パー");
|
|
||||||
|
|
||||||
Scanner sc = new Scanner(System.in);
|
while ( !winflag ) {
|
||||||
int playerHand;
|
|
||||||
playerHand= sc.nextInt();
|
System.out.println("じゃんけんを行います。");
|
||||||
System.out.println(playerHand);
|
System.out.println("あなたの出す手を入力してください。");
|
||||||
|
System.out.println("0:グー, 1:チョキ, 2:パー");
|
||||||
if(playerHand == 0) {
|
|
||||||
System.out.println("あなたはグーを出しました。");
|
Scanner sc = new Scanner(System.in);
|
||||||
}else if(playerHand == 1) {
|
int playerHand = sc.nextInt();
|
||||||
System.out.println("あなたはチョキを出しました。");
|
switch ( playerHand ) {
|
||||||
}else {
|
case 0 :
|
||||||
System.out.println("あなたはパーを出しました。");
|
System.out.println("あなたはグーを出しました。");
|
||||||
}
|
break;
|
||||||
|
case 1 :
|
||||||
int num = (int)(Math.random()*3);
|
System.out.println("あなたはチョキを出しました。");
|
||||||
int npcHand = num;
|
break;
|
||||||
|
case 2 :
|
||||||
if(npcHand ==0) {
|
System.out.println("あなたはパーを出しました。");
|
||||||
System.out.println("相手はグーを出しました。");
|
break;
|
||||||
}else if(npcHand ==1) {
|
// default :
|
||||||
System.out.println("相手はチョキを出しました。");
|
// System.out.println("不正な入力です。");
|
||||||
}else {
|
// System.exit(0);
|
||||||
System.out.println("相手はパーを出しました。");
|
}
|
||||||
}
|
|
||||||
|
int npcHand = (int)( Math.random()*3 );
|
||||||
if(playerHand == 0 && npcHand ==1 || playerHand == 1 && npcHand ==2 || playerHand == 2 &&npcHand ==0) {
|
switch ( npcHand ) {
|
||||||
System.out.println("あなたの勝ちです。");
|
case 0 :
|
||||||
winFlag = true;
|
System.out.println("相手はグーを出しました。");
|
||||||
}else if(playerHand == npcHand) {
|
break;
|
||||||
System.out.println("あいこです。");
|
case 1 :
|
||||||
System.out.println();
|
System.out.println("相手はチョキを出しました。");
|
||||||
continue;
|
break;
|
||||||
}else {
|
case 2 :
|
||||||
System.out.println("あなたの負けです。");
|
System.out.println("相手はパーを出しました。");
|
||||||
System.out.println();
|
break;
|
||||||
continue;
|
}
|
||||||
|
|
||||||
|
if ( playerHand == npcHand ) {
|
||||||
|
System.out.println("引き分けました。");
|
||||||
|
System.out.println("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ((playerHand==0)&&(npcHand==2)) ||
|
||||||
|
((playerHand==1)&&(npcHand==0)) ||
|
||||||
|
((playerHand==2)&&(npcHand==1)) ) {
|
||||||
|
System.out.println("負けました。");
|
||||||
|
System.out.println("");
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
System.out.println("勝ちました。");
|
||||||
|
winflag = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,33 @@ public class Question5_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
System.out.println("今日の運勢を占います。");
|
System.out.println("今日の運勢を占います。");
|
||||||
int num = (int)(Math.random()*6);
|
|
||||||
|
int num = (int)( Math.random()*5+1 );
|
||||||
|
// System.out.println(num);
|
||||||
|
|
||||||
switch(num) {
|
switch (num) {
|
||||||
case 0:
|
case 0 :
|
||||||
System.out.println("あなたの運勢は「大吉」です");
|
System.out.println("あなたの運勢は「大吉」です。");
|
||||||
break;
|
break;
|
||||||
|
case 1 :
|
||||||
case 1:
|
System.out.println("あなたの運勢は「吉」です。");
|
||||||
System.out.println("あなたの運勢は「吉」です");
|
break;
|
||||||
break;
|
case 2 :
|
||||||
|
System.out.println("あなたの運勢は「中吉」です。");
|
||||||
case 2:
|
break;
|
||||||
System.out.println("あなたの運勢は「中吉」");
|
case 3 :
|
||||||
break;
|
System.out.println("あなたの運勢は「小吉」です。");
|
||||||
|
break;
|
||||||
case 3:
|
case 4 :
|
||||||
System.out.println("あなたの運勢は「小吉」");
|
System.out.println("あなたの運勢は「末吉」です。");
|
||||||
break;
|
break;
|
||||||
|
case 5 :
|
||||||
case 4:
|
System.out.println("あなたの運勢は「凶」です。");
|
||||||
System.out.println("あなたの運勢は「末吉」");
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
System.out.println("あなたの運勢は「凶」");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,39 +4,44 @@ public class Question5_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
System.out.println("1つ目の数値を入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
int num1 = sc.nextInt();
|
|
||||||
System.out.println("2つ目の数値を入力してください");
|
|
||||||
int num2 = sc.nextInt();
|
|
||||||
System.out.println("計算方法を選択してください");
|
|
||||||
sc.nextLine();
|
|
||||||
String choice = sc.nextLine();
|
|
||||||
|
|
||||||
switch(choice) {
|
|
||||||
case "+":
|
int num1, num2;
|
||||||
System.out.println(num1 + num2);
|
String choice;
|
||||||
break;
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
case "-":
|
System.out.println("1つ目の数値を入力してください");
|
||||||
System.out.println(num1 - num2);
|
num1 = sc.nextInt();
|
||||||
break;
|
|
||||||
|
System.out.println("2つ目の数値を入力してください");
|
||||||
case "*":
|
num2 = sc.nextInt();
|
||||||
System.out.println(num1 * num2);
|
|
||||||
break;
|
System.out.println("計算方法を選択してください");
|
||||||
|
choice = sc.next();
|
||||||
case "/":
|
|
||||||
System.out.println(num1 / num2);
|
sc.close();
|
||||||
break;
|
|
||||||
|
switch (choice) {
|
||||||
case "%":
|
case "+" :
|
||||||
System.out.println(num1 % num2);
|
System.out.println(num1+num2);
|
||||||
break;
|
break;
|
||||||
|
case "-" :
|
||||||
default:
|
System.out.println(num1-num2);
|
||||||
System.out.println("計算に失敗しました");
|
break;
|
||||||
|
case "*" :
|
||||||
|
System.out.println(num1*num2);
|
||||||
|
break;
|
||||||
|
case "/" :
|
||||||
|
System.out.println((double)num1/(double)num2);
|
||||||
|
break;
|
||||||
|
case "%" :
|
||||||
|
System.out.println(num1%num2);
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
System.out.println("計算に失敗しました");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,55 +4,64 @@ public class Question5_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
System.out.println("=========================================");
|
|
||||||
System.out.println(" ゲームの説明 ");
|
|
||||||
System.out.println("=========================================");
|
|
||||||
|
|
||||||
System.out.println("これからハイ&ローゲームを行います。");
|
System.out.println("=========================================\n"
|
||||||
System.out.println("ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。");
|
+ " ゲームの説明\n"
|
||||||
System.out.println();
|
+ "=========================================\n"
|
||||||
|
+ "これからハイ&ローゲームを行います。\n"
|
||||||
|
+ "ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "=========================================\n"
|
||||||
|
+ " ゲーム開始\n"
|
||||||
|
+ "=========================================");
|
||||||
|
|
||||||
System.out.println("=========================================");
|
int dealerCard = (int)( Math.random()*12+1 );
|
||||||
System.out.println(" ゲーム開始 ");
|
// dealerCard = ;
|
||||||
System.out.println("=========================================");
|
System.out.println("ディーラーのカードは"+dealerCard+"です");
|
||||||
|
|
||||||
|
int myCard = (int)( Math.random()*12+1 );
|
||||||
|
// myCard = ;
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
int dealerCard = (int)(Math.random()*13)+1;
|
|
||||||
System.out.println("ディーラーのカードは" + dealerCard + "です");
|
|
||||||
int myCard = (int)(Math.random()*13)+1;
|
|
||||||
System.out.println();
|
|
||||||
System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。");
|
System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。");
|
||||||
System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。");
|
System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。");
|
||||||
|
|
||||||
|
String jedgement;
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String judgement = sc.nextLine();
|
jedgement = sc.next();
|
||||||
System.out.println("あなたのカードは" + myCard + "です");
|
sc.close();
|
||||||
|
|
||||||
|
System.out.println("あなたのカードは"+myCard+"です");
|
||||||
|
|
||||||
System.out.println();
|
System.out.println("");
|
||||||
System.out.println("=========================================");
|
|
||||||
System.out.println(" 勝敗判定" );
|
|
||||||
System.out.println("=========================================");
|
|
||||||
|
|
||||||
switch(judgement) {
|
System.out.println("=========================================\n"
|
||||||
case "H":
|
+ " 勝敗判定\n"
|
||||||
if(myCard > dealerCard || myCard == dealerCard) {
|
+ "=========================================");
|
||||||
System.out.println("あなたの勝ちです");
|
|
||||||
|
switch (jedgement) {
|
||||||
|
case "H" :
|
||||||
|
if (myCard>=dealerCard) {
|
||||||
|
System.out.println("あなたの勝ちです");
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("あなたの負けです");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "L" :
|
||||||
|
if (myCard<=dealerCard) {
|
||||||
|
System.out.println("あなたの勝ちです");
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("あなたの負けです");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default :
|
||||||
|
System.out.println("不正な値が入力されました");
|
||||||
break;
|
break;
|
||||||
}else{
|
|
||||||
System.out.println("あなたの負けです");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "L":
|
|
||||||
if(myCard < dealerCard || myCard == dealerCard) {
|
|
||||||
System.out.println("あなたの勝ちです");
|
|
||||||
break;
|
|
||||||
}else{
|
|
||||||
System.out.println("あなたの負けです");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
System.out.println("不正な値が入力されました");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ public class Question6_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 0; i < 100; i++){
|
|
||||||
|
for ( int i = 0 ; i<100 ; i++ ) {
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,18 @@ public class Question6_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
System.out.println("■■■■■");
|
|
||||||
|
|
||||||
for(int i = 0; i < 5;i++) {
|
StringBuilder square = new StringBuilder();
|
||||||
System.out.print("■");
|
for ( int i=0 ; i<5 ; i++ ) {
|
||||||
|
square.append('\u25A0'); // ■ = \u25A0
|
||||||
}
|
}
|
||||||
|
System.out.println(square);
|
||||||
|
|
||||||
|
// 1009
|
||||||
|
for ( int i=0 ; i<5 ; i++ ) {
|
||||||
|
System.out.print("\u25A0");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ public class Question6_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 0;i < 100; i++) {
|
|
||||||
if(i % 2 == 0) {
|
for ( int i = 0 ; i<=100 ; i++ ) {
|
||||||
|
if ( i%2 == 0 ) {
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,22 @@ public class Question6_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 1; i <= 49; i++) {
|
|
||||||
if(i % 3 == 0 && i % 5 == 0) {
|
for ( int i = 1 ; i<50 ; i++ ) {
|
||||||
System.out.println("fizzbuzz");
|
|
||||||
}else if(i % 5 == 0) {
|
if ( (i%3 == 0) && (i%5 == 0) ) {
|
||||||
System.out.println("buzz");
|
System.out.println("fizzbuzz");
|
||||||
}else if(i % 3 == 0 ) {
|
continue;
|
||||||
|
} else if ( i%3==0 ) {
|
||||||
System.out.println("fizz");
|
System.out.println("fizz");
|
||||||
}else {
|
} else if ( i%5==0 ) {
|
||||||
|
System.out.println("buzz");
|
||||||
|
} else {
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,20 @@ public class Question6_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 0; i < 10; i++) {
|
|
||||||
int num = (int)(Math.random()*3);
|
int rand;
|
||||||
if(num !=2) {
|
for ( int i = 0 ; i<10 ; i++) {
|
||||||
System.out.println(num);
|
|
||||||
|
rand = (int)( Math.random()*3 );
|
||||||
|
|
||||||
|
if ( rand==2 ) {
|
||||||
|
// no output
|
||||||
|
} else {
|
||||||
|
System.out.println(rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,23 @@ public class Question6_6 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 0; i < 5; i++) {
|
|
||||||
System.out.println("■■■■■");
|
StringBuilder square = new StringBuilder();
|
||||||
|
for ( int i=0 ; i<5 ; i++ ) {
|
||||||
|
square.append('\u25A0'); // ■ = \u25A0
|
||||||
}
|
}
|
||||||
|
for ( int i=0 ; i<5 ; i++ ) {
|
||||||
|
System.out.println(square);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1009
|
||||||
|
for (int j=0 ; j<5 ; j++ ) {
|
||||||
|
for ( int i=0 ; i<5 ; i++ ) {
|
||||||
|
System.out.print("\u25A0");
|
||||||
|
}
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,29 @@ public class Question6_7 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
for(int i = 1; i <= 9; i++) {
|
|
||||||
for(int j = 1; j <= 9; j++) {
|
StringBuilder sb = new StringBuilder();
|
||||||
System.out.printf("%2d",i * j);
|
for ( int i=1 ; i<=9 ; i++ ) {
|
||||||
|
for ( int j=1 ; j<=9 ; j++ ) {
|
||||||
|
if ( j>=2 ) {
|
||||||
|
sb.append(" "); // *2以降には空白を追加する
|
||||||
|
}
|
||||||
|
sb.append(i*j); // 計算結果を文字列として追加していく
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println(sb);
|
||||||
|
sb.delete(0,sb.length()); // 追記した文字列をクリアする
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1009
|
||||||
|
for ( int i=1 ; i<=9 ; i++ ) {
|
||||||
|
for ( int j=1 ; j<=9 ; j++ ) {
|
||||||
|
System.out.print(i*j);
|
||||||
|
if ( j==9 ) { continue; }
|
||||||
|
System.out.print(" ");
|
||||||
|
}
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,16 @@ public class Question7_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[] nums = {1, 3, 5, 7, 9};
|
|
||||||
|
int nums[] = new int[5];
|
||||||
|
nums[0] = 1;
|
||||||
|
nums[1] = 3;
|
||||||
|
nums[2] = 5;
|
||||||
|
nums[3] = 7;
|
||||||
|
nums[4] = 9;
|
||||||
|
|
||||||
System.out.println(nums[1]);
|
System.out.println(nums[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,19 @@ public class Question7_10 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
int[] nums = new int[100];
|
int[] nums = new int[100];
|
||||||
|
|
||||||
for(int i = 0; i < nums.length; i++) {
|
// ArrayIndexOutOfBoundException
|
||||||
nums[i] = i + 1;
|
// for ( int i=1 ; i<=100 ; i++ ) {
|
||||||
}
|
// nums[i] = i+1;
|
||||||
for(int i = 0; i < nums.length; i++) {
|
// }
|
||||||
|
|
||||||
|
for ( int i=0 ; i<100 ; i++ ) {
|
||||||
|
nums[i] = i+1;
|
||||||
System.out.println(nums[i]);
|
System.out.println(nums[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ public class Question7_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[] nums = {1, 10, 100};
|
|
||||||
System.out.println(nums[0] + nums[2]);
|
int[] nums = {1 ,10, 100};
|
||||||
|
|
||||||
|
System.out.println(nums[0]+nums[2]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ public class Question7_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String[] str = {"森", "山", "沼", "島", "平地"};
|
|
||||||
for(int i = 0; i <= 4; i++) {
|
String[] str = {"森","山","沼","島","平地"};
|
||||||
|
|
||||||
|
for ( int i=0 ; i<str.length ; i++ ) {
|
||||||
System.out.println(str[i]);
|
System.out.println(str[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ public class Question7_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[] nums = new int[1000];
|
|
||||||
for(int i = 0; i < 1000; i++) {
|
int nums[] = new int[1000];
|
||||||
nums[i] = i + 1;
|
|
||||||
}
|
for ( int i=1 ; i<=nums.length ; i++ ) {
|
||||||
for(int i = 0; i < 1000; i++) {
|
nums[i-1] = i;
|
||||||
System.out.println(nums[i]);
|
System.out.println(nums[i-1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,9 +3,12 @@ public class Question7_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String[] str = {"森", "山", "沼", "島", "平地"};
|
|
||||||
int num = (int)(Math.random()*5);
|
String[] str = {"森","山","沼","島","平地"};
|
||||||
|
|
||||||
|
int num = (int)( Math.random()*5 );
|
||||||
System.out.println(str[num]);
|
System.out.println(str[num]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ public class Question7_6 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String[] str = {"森", "山", "沼", "島", "平地"};
|
|
||||||
for(int i = 4; i >=0; i--) {
|
String[] str = {"森","山","沼","島","平地"};
|
||||||
System.out.println(str[i]);
|
for ( int i=str.length ; i>0 ; i-- ) {
|
||||||
|
System.out.println(str[i-1]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,26 +3,17 @@ public class Question7_7 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String[][] timetable = {
|
|
||||||
{"国語", "社会", "国語", "理科", "社会"},
|
|
||||||
{"英語", "数学", "英語", "数学", "国語"},
|
|
||||||
{"理科", "国語", "理科", "国語" ,"理科"},
|
|
||||||
{"社会", "社会", "数学", "社会", "数学"},
|
|
||||||
{"数学", "英語", "英語", "理科", "英語"},
|
|
||||||
};
|
|
||||||
|
|
||||||
System.out.println("\t 月\t 火\t 水\t 木\t 金");
|
String[][] table = {
|
||||||
for(int i = 0; i < 5; i++) {
|
{"国語","社会","国語","理科","社会"},
|
||||||
System.out.print((i + 1) + "時間目");
|
{"英語","数学","英語","数学","国語"},
|
||||||
|
{"理科","国語","理科","国語","理科"},
|
||||||
for(int j = 0; j < 5; j++) {
|
{"社会","社会","数学","社会","数学"},
|
||||||
System.out.print("\t" + timetable[i][j]);
|
{"数学","英語","英語","理科","英語"}
|
||||||
}
|
};
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(timetable[1][4]);
|
System.out.println(table[1][4]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,14 +3,18 @@ public class Question7_8 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[][] nums = {
|
|
||||||
{1, 3, 5, 7},
|
int[][] array = {
|
||||||
{11, 13, 17, 19, 23, 29}
|
{1,3,5,7},
|
||||||
|
{11,13,17,19,23,29}
|
||||||
};
|
};
|
||||||
for(int i = 0; i < nums.length; i++) {
|
|
||||||
for(int j = 0; j < nums[i].length; j++) {
|
for ( int i=0 ; i<array.length ; i++) {
|
||||||
System.out.println(nums[i][j]);
|
for ( int j=0 ; j<array[i].length ; j++ ) {
|
||||||
|
System.out.println(array[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,21 +3,22 @@ public class Question7_9 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[][] nums = {
|
|
||||||
{1, 3, 5, 7},
|
|
||||||
{11, 13, 17, 19, 23, 29}
|
|
||||||
};
|
|
||||||
int sum = 0;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < nums.length; i++) {
|
int[][] array = {
|
||||||
for(int j = 0; j < nums[i].length; j++) {
|
{1,3,5,7},
|
||||||
sum += nums[i][j];
|
{11,13,17,19,23,29}
|
||||||
|
};
|
||||||
|
|
||||||
|
int count=0;
|
||||||
|
double sum=0;
|
||||||
|
for ( int i=0 ; i<array.length ; i++) {
|
||||||
|
for ( int j=0 ; j<array[i].length ; j++ ) {
|
||||||
|
sum += array[i][j];
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float ave = (float)sum / count;
|
System.out.println(sum/count);
|
||||||
System.out.println(ave);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ public class Question8_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
hello();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
hello() ;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void hello() {
|
public static void hello() {
|
||||||
System.out.println("こんにちは");
|
System.out.println("こんにちは");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ public class Question8_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
hello("山田");
|
hello("山田");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void hello( String name ) {
|
||||||
|
System.out.println("こんにちは。"+name+"です。");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void hello(String str) {
|
|
||||||
System.out.println("こんにちは" + str + "です");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ public class Question8_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
String str = hello();
|
|
||||||
|
String str;
|
||||||
|
str = hello();
|
||||||
|
|
||||||
System.out.println(str);
|
System.out.println(str);
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static String hello() {
|
public static String hello() {
|
||||||
return "こんにちは";
|
return "こんにちは";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ public class Question8_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int total = 0;
|
|
||||||
total = sum(1, 2);
|
int sum;
|
||||||
System.out.println(total);
|
int x = 1;
|
||||||
|
int y = 2;
|
||||||
|
|
||||||
|
sum = sum(x,y);
|
||||||
|
System.out.println(sum);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int sum( int x, int y ) {
|
||||||
|
return x+y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int sum(int x, int y) {
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,24 @@ public class Question8_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
System.out.println("1つ目の数値を入力してください");
|
|
||||||
|
int num1, num2;
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
int num1;
|
|
||||||
|
System.out.println("1つ目の数値を入力してください");
|
||||||
num1 = sc.nextInt();
|
num1 = sc.nextInt();
|
||||||
System.out.println(num1);
|
|
||||||
|
|
||||||
System.out.println("2つ目の数値を入力してください");
|
System.out.println("2つ目の数値を入力してください");
|
||||||
int num2;
|
|
||||||
num2 = sc.nextInt();
|
num2 = sc.nextInt();
|
||||||
System.out.println(num2);
|
|
||||||
|
|
||||||
int total = 0;
|
sc.close();
|
||||||
total = sum(num1, num2);
|
|
||||||
System.out.println(total);
|
System.out.println(sum(num1,num2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int sum(int num1, int num2) {
|
public static int sum( int x, int y ) {
|
||||||
return num1 + num2;
|
return x+y;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Question8_6 {
|
public class Question8_6 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int[] array = addArray(10, 20);
|
|
||||||
System.out.println(Arrays.toString(array));
|
int[] array = addArray(10,20);
|
||||||
|
|
||||||
|
System.out.println(array[0]);
|
||||||
|
System.out.println(array[1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] addArray(int x, int y) {
|
public static int[] addArray( int x, int y ) {
|
||||||
int[] array = new int[2];
|
|
||||||
|
int array[] = new int[2];
|
||||||
array[0] = x;
|
array[0] = x;
|
||||||
array[1] = y;
|
array[1] = y;
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,28 @@ public class Question8_7 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
printValue("こんにちは");
|
printValue("こんにちは");
|
||||||
printValue("100");
|
printValue(100);
|
||||||
printValue("10.1");
|
printValue(10.1F);
|
||||||
printValue("A");
|
printValue('A');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printValue( String arg ) {
|
||||||
|
System.out.println("引数は"+arg+"です");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printValue( int arg ) {
|
||||||
|
System.out.println("引数は"+arg+"です");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printValue(String str) {
|
public static void printValue( float arg ) {
|
||||||
System.out.println("引数は" + str + "です");
|
System.out.println("引数は"+arg+"です");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printValue(int i) {
|
public static void printValue( char arg ) {
|
||||||
System.out.println("引数は" + i + "です");
|
System.out.println("引数は"+arg+"です");
|
||||||
}
|
|
||||||
|
|
||||||
public static void printValue(float f) {
|
|
||||||
System.out.println("引数は" + f + "です");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void printValue(char ch) {
|
|
||||||
System.out.println("引数は" + ch + "です");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,23 @@ public class Question8_8 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
int total = 0;
|
|
||||||
total = sum(1, 2);
|
|
||||||
System.out.println(total);
|
|
||||||
|
|
||||||
total = sum(1, 2, 3);
|
|
||||||
System.out.println(total);
|
|
||||||
|
|
||||||
total = sum(1, 2, 3, 4);
|
|
||||||
System.out.println(total);
|
|
||||||
|
|
||||||
|
System.out.println(sum(1,2));
|
||||||
|
System.out.println(sum(1,2,3));
|
||||||
|
System.out.println(sum(1,2,3,4));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int sum(int... numbers) {
|
public static int sum( int x1, int x2 ) {
|
||||||
int total = 0;
|
return x1+x2;
|
||||||
for(int n : numbers) {
|
|
||||||
total += n;
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int sum( int x1, int x2, int x3 ) {
|
||||||
|
return x1+x2+x3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int sum( int x1, int x2, int x3, int x4 ) {
|
||||||
|
return x1+x2+x3+x4;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ public class Question9_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Util.hello();
|
|
||||||
|
Util util = new Util();
|
||||||
|
util.hello();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ public class Question9_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
common.Util.showSum(1, 2);
|
|
||||||
|
common.Util util = new common.Util();
|
||||||
|
util.showSum(1,2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import common.Util;
|
import common.Util;
|
||||||
|
|
||||||
public class Question9_3 {
|
public class Question9_3 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Util.showSum(1, 2);
|
|
||||||
|
Util util = new Util();
|
||||||
|
util.showSum(1,2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
public static void hello() {
|
|
||||||
|
public void hello() {
|
||||||
System.out.println("こんにちは");
|
System.out.println("こんにちは");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package common;
|
package common;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
public static void showSum(int num1, int num2) {
|
|
||||||
System.out.println(num1 + num2);
|
public void showSum(int num1,int num2) {
|
||||||
|
System.out.println(num1+num2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
public class Calculation {
|
public class Calculation {
|
||||||
int baseNum;
|
|
||||||
|
|
||||||
|
int baseNum;
|
||||||
|
|
||||||
public void add(int num) {
|
public void add(int num) {
|
||||||
this.baseNum += num;
|
this.baseNum += num;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Car {
|
public class Car {
|
||||||
|
|
||||||
String color;
|
String color;
|
||||||
int gasoline;
|
int gasoline;
|
||||||
|
|
||||||
public int run() {
|
public int run() {
|
||||||
this.gasoline -= 1;
|
|
||||||
if(this.gasoline >= 0) {
|
this.gasoline--;
|
||||||
Random rand = new Random();
|
|
||||||
int num = rand.nextInt(15) + 1;
|
if (this.gasoline>=0) {
|
||||||
return num;
|
return (int)(Math.random()*15+1) ;
|
||||||
}else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ public class Question10_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
User user = new User();
|
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
user.id = 1000;
|
user.id = 1000;
|
||||||
user.name = "山田太郎";
|
user.name = "山田太郎";
|
||||||
|
|
||||||
System.out.println(user.id);
|
System.out.println(user.id);
|
||||||
System.out.println(user.name);
|
System.out.println(user.name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ public class Question10_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
User user = new User();
|
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
user.id = 2000;
|
user.id = 2000;
|
||||||
user.name = "佐藤二郎";
|
user.name = "佐藤二郎";
|
||||||
|
|
||||||
user.printProfile();
|
user.printProfile();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ public class Question10_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Student student = new Student();
|
|
||||||
|
|
||||||
|
Student student = new Student();
|
||||||
student.studentId = 10;
|
student.studentId = 10;
|
||||||
student.name = "田中二郎";
|
student.name = "田中二郎";
|
||||||
student.mail = "test@mail.com";
|
student.mail = "test@mail.com";
|
||||||
@@ -13,7 +13,8 @@ public class Question10_3 {
|
|||||||
System.out.println(student.studentId);
|
System.out.println(student.studentId);
|
||||||
System.out.println(student.name);
|
System.out.println(student.name);
|
||||||
System.out.println(student.mail);
|
System.out.println(student.mail);
|
||||||
System.out.println(student.password );
|
System.out.println(student.password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ public class Question10_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Calculation cal = new Calculation();
|
|
||||||
|
|
||||||
cal.baseNum = 100;
|
Calculation calculation = new Calculation();
|
||||||
|
calculation.baseNum = 100;
|
||||||
|
calculation.add(100);
|
||||||
|
|
||||||
cal.add(100);
|
System.out.println(calculation.baseNum);
|
||||||
|
|
||||||
System.out.println(cal.baseNum);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ public class Question10_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Car car = new Car();
|
Car car = new Car();
|
||||||
|
car.color = "赤";
|
||||||
car.color ="赤";
|
|
||||||
car.gasoline = 50;
|
car.gasoline = 50;
|
||||||
|
int progress = car.run();
|
||||||
int y =car.run();
|
System.out.println(car.color+"色の車は"+progress+"進みました");
|
||||||
|
|
||||||
System.out.println(car.color + "色の車は" + y + "進みました");
|
|
||||||
System.out.println(car.gasoline);
|
System.out.println(car.gasoline);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,27 +3,26 @@ public class Question10_6 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Car car = new Car();
|
|
||||||
|
|
||||||
|
Car car = new Car();
|
||||||
car.color = "赤";
|
car.color = "赤";
|
||||||
car.gasoline = 50;
|
car.gasoline = 50;
|
||||||
int goal = 300;
|
|
||||||
int totaldistance = 0;
|
|
||||||
int time = 0;
|
|
||||||
|
|
||||||
while(totaldistance < goal) {
|
int distance = 300;
|
||||||
int y = car.run();
|
int nRuns = 0;
|
||||||
if(y == -1) {
|
while (true) {
|
||||||
System.out.println(car.color + "色の車は目的地に到達できませんでした");
|
distance -= car.run();
|
||||||
|
nRuns++;
|
||||||
|
if (car.gasoline<0) {
|
||||||
|
System.out.println(car.color+"色の車は、目的地に到達できませんでした。");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (distance<=0) {
|
||||||
|
System.out.println(car.color+"色の車は、目的地にまで"+nRuns+"時間かかりました。残りのガソリンは、"+car.gasoline+"リットルです。");
|
||||||
break;
|
break;
|
||||||
}else{
|
|
||||||
totaldistance += y;
|
|
||||||
time += 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(car.color + "色の車は目的地にまで" + time + "時間かかりました。" +
|
|
||||||
"残りのガソリンは、" + car.gasoline + "リットルです");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ public class Question10_7 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
User[] userList = new User[3];
|
User[] userList = new User[3];
|
||||||
|
|
||||||
User user1 = new User();
|
User user1 = new User();
|
||||||
User user2 = new User();
|
User user2 = new User();
|
||||||
User user3 = new User();
|
User user3 = new User();
|
||||||
@@ -19,9 +21,13 @@ public class Question10_7 {
|
|||||||
userList[1] = user2;
|
userList[1] = user2;
|
||||||
userList[2] = user3;
|
userList[2] = user3;
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
// for (int i=0;i<userList.length;i++) {
|
||||||
userList[i].printProfile();
|
// userList[i].printProfile();
|
||||||
|
// }
|
||||||
|
for (User user:userList) {
|
||||||
|
user.printProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,44 +3,39 @@ public class Question10_8 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
|
Car[] carList = new Car[3];
|
||||||
|
|
||||||
Car car1 = new Car();
|
Car car1 = new Car();
|
||||||
car1.color = "赤";
|
car1.color = "赤";
|
||||||
car1.gasoline = 50;
|
car1.gasoline = 50;
|
||||||
|
|
||||||
Car car2 = new Car();
|
Car car2 = new Car();
|
||||||
car2.color = "青";
|
car2.color = "青";
|
||||||
car2.gasoline = 60;
|
car2.gasoline = 60;
|
||||||
|
|
||||||
Car car3 = new Car();
|
Car car3 = new Car();
|
||||||
car3.color = "黄";
|
car3.color = "黄";
|
||||||
car3.gasoline = 70;
|
car3.gasoline = 70;
|
||||||
|
|
||||||
Car[] cars = new Car[3];
|
carList[0] = car1;
|
||||||
cars[0] = car1;
|
carList[1] = car2;
|
||||||
cars[1] = car2;
|
carList[2] = car3;
|
||||||
cars[2] = car3;
|
|
||||||
|
|
||||||
int goal = 300;
|
for (Car car:carList) {
|
||||||
|
int distance = 300;
|
||||||
for(int i = 0; i < 3; i++) {
|
int nRuns = 0;
|
||||||
int totaldistance = 0;
|
while (true) {
|
||||||
int time = 0;
|
distance -= car.run();
|
||||||
int y = 0;
|
nRuns++;
|
||||||
|
if (car.gasoline<0) {
|
||||||
while(totaldistance < goal) {
|
System.out.println(car.color+"色の車は、目的地に到達できませんでした。");
|
||||||
y = cars[i].run();
|
break;
|
||||||
if(y == -1) {
|
}
|
||||||
|
if (distance<=0) {
|
||||||
|
System.out.println(car.color+"色の車は、目的地にまで"+nRuns+"時間かかりました。残りのガソリンは、"+car.gasoline+"リットルです。");
|
||||||
break;
|
break;
|
||||||
}else {
|
|
||||||
totaldistance += y;
|
|
||||||
time += 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(y == -1) {
|
|
||||||
System.out.println(cars[i].color + "色の車は、目的地に到達できませんでした");
|
|
||||||
}else {
|
|
||||||
System.out.println(cars[i].color + "色の車は、目的地にまで" + time + "時間かかりました。"
|
|
||||||
+ "残りのガソリンは、" + cars[i].gasoline + "リットルです");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
|
|
||||||
int studentId;
|
int studentId;
|
||||||
String name;
|
String name, mail, password;
|
||||||
String mail;
|
|
||||||
String password;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
|
|
||||||
public void printProfile() {
|
public void printProfile() {
|
||||||
System.out.println("ID" + this.id + ":" + this.name);
|
System.out.println("ID"+this.id+":"+this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
|
|
||||||
public class Atm {
|
public class Atm {
|
||||||
int credit = 100000;
|
|
||||||
|
|
||||||
public void withdraw(Wallet wallet, int money) {
|
int credit;
|
||||||
if(credit < money) {
|
|
||||||
|
public Atm () {
|
||||||
|
this.credit = 100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void withdraw( Wallet wallet , int money ) {
|
||||||
|
if ( this.credit < money ) {
|
||||||
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
System.out.println("預金残高不足です。現金の引き出しに失敗しました。");
|
||||||
}else {
|
} else {
|
||||||
credit -= money;
|
this.credit = this.credit - money;
|
||||||
wallet.money += money;
|
wallet.money = wallet.money + money;
|
||||||
System.out.println("ATMの残り残高は" + credit + "です");
|
System.out.println("ATMの残り残高は"+this.credit+"です");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
public class Cat {
|
public class Cat {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
//ⅰ
|
public Cat() {
|
||||||
Cat(){
|
|
||||||
this.name = "タマ";
|
this.name = "タマ";
|
||||||
}
|
}
|
||||||
|
|
||||||
//ⅱ
|
public Cat( String name ) {
|
||||||
public Cat(String name) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
|
||||||
public class Jam {
|
public class Jam {
|
||||||
|
|
||||||
String material;
|
String material;
|
||||||
|
|
||||||
public Jam(String material) {
|
public Jam( String jam ) {
|
||||||
this.material = material;
|
this.material = jam;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ public class Question11_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Wallet wallet = new Wallet();
|
Wallet wallet = new Wallet();
|
||||||
User user = new User();
|
|
||||||
|
|
||||||
|
|
||||||
wallet.money = 10000;
|
wallet.money = 10000;
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
user.name = "太郎";
|
user.name = "太郎";
|
||||||
user.wallet = wallet;
|
user.wallet = wallet;
|
||||||
|
|
||||||
user.confirmWallet();
|
user.confirmWallet();
|
||||||
user.useMoney(1000);
|
user.useMoney(1000);
|
||||||
user.confirmWallet();
|
user.confirmWallet();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,18 @@ public class Question11_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Wallet wallet = new Wallet();
|
Wallet wallet = new Wallet();
|
||||||
|
wallet.money = 10000;
|
||||||
|
|
||||||
Atm atm = new Atm();
|
Atm atm = new Atm();
|
||||||
|
|
||||||
wallet.money = 10000;
|
atm.withdraw(wallet,100000);
|
||||||
atm.withdraw(wallet, 100000);
|
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ public class Question11_3 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Cat cat1 = new Cat();
|
|
||||||
Cat cat2 = new Cat("ミケ");
|
|
||||||
|
|
||||||
|
Cat cat1 = new Cat();
|
||||||
System.out.println(cat1.name);
|
System.out.println(cat1.name);
|
||||||
|
|
||||||
|
Cat cat2 = new Cat("ミケ");
|
||||||
System.out.println(cat2.name);
|
System.out.println(cat2.name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ public class Question11_4 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Student student = new Student();
|
Student student = new Student();
|
||||||
student.name = "太郎";
|
student.name = "太郎";
|
||||||
Student.group= "A";
|
student.group = "A";
|
||||||
Student.teacher = "山田";
|
student.teacher = "山田";
|
||||||
|
|
||||||
student.studentProfile();
|
student.studentProfile();
|
||||||
Student.groupProfile();
|
student.groupProfile();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ public class Question11_5 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Jam jam = new Jam("ブルーベリー");
|
Jam jam = new Jam("ブルーベリー");
|
||||||
Toast toast = new Toast(jam);
|
Toast toast = new Toast(jam);
|
||||||
|
|
||||||
toast.taste();
|
toast.taste();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
static String group;
|
static String group;
|
||||||
static String teacher;
|
static String teacher;
|
||||||
|
|
||||||
public void studentProfile() {
|
public void studentProfile() {
|
||||||
System.out.println(this.name + "は" + group + "教室の生徒です。");
|
System.out.println(this.name+"は"+this.group+"教室の生徒です。");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void groupProfile() {
|
public void groupProfile() {
|
||||||
System.out.println(group + "教室の担任は" + teacher + "先生です。");
|
System.out.println(this.group+"教室の担任は"+this.teacher+"先生です。");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
|
|
||||||
public class Toast {
|
public class Toast {
|
||||||
|
|
||||||
Jam jam;
|
Jam jam;
|
||||||
|
|
||||||
public Toast(Jam jam) {
|
public Toast(Jam jam) {
|
||||||
this.jam = jam;
|
this.jam = jam;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void taste() {
|
public void taste() {
|
||||||
System.out.println(this.jam.material + "味のトーストです。");
|
System.out.println(jam.material+"味のトーストです。");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
Wallet wallet;
|
Wallet wallet;
|
||||||
|
|
||||||
public void useMoney(int money) {
|
public void useMoney( int money ) {
|
||||||
this.wallet.money -= money;
|
this.wallet.money = this.wallet.money - money;
|
||||||
System.out.println(this.name + "は財布の中のお金を" +
|
System.out.println(this.name+"は財布の中のお金を"+money+"円使用しました");
|
||||||
money + "円使用しました");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void confirmWallet() {
|
public void confirmWallet() {
|
||||||
System.out.println(this.name + "の財布の中の残額は" +
|
System.out.println(this.name+"の財布の中の残額は"+this.wallet.money+"円です");
|
||||||
this.wallet.money + "円です");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
public class Wallet {
|
public class Wallet {
|
||||||
|
|
||||||
int money;
|
int money;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
public String name = "アイテムA";
|
|
||||||
|
private String item;
|
||||||
public String getName() {
|
|
||||||
return name;
|
public Item() {
|
||||||
|
this.item = "アイテムA";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,19 @@ public class Question12_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
|
||||||
user.setId(1000);
|
user.setId(1000);
|
||||||
user.setName("リゾーム太郎");
|
user.setName("リゾーム太郎");
|
||||||
user.setAddress("rhizome@hogehoge.com");
|
user.setMail("rhizome@hogehoge.com");
|
||||||
user.setPass("12345");
|
user.setPass("12345");
|
||||||
|
|
||||||
System.out.println("ID :" + user.getId());
|
System.out.println("ID :"+user.getId());
|
||||||
System.out.println("名前 :" + user.getName());
|
System.out.println("名前 :"+user.getName());
|
||||||
System.out.println("メールアドレス :" + user.getAddress());
|
System.out.println("メールアドレス :"+user.getMail());
|
||||||
System.out.println("パスワード :" + user.getPass());
|
System.out.println("パスワード :"+user.getPass());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ public class Question12_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Item item = new Item();
|
Item item = new Item();
|
||||||
System.out.println(item.getName());
|
System.out.println(item.getItem());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
public int id;
|
|
||||||
public String name;
|
private int Id;
|
||||||
public String address;
|
private String name;
|
||||||
public String pass;
|
private String mail;
|
||||||
|
private String pass;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return Id;
|
||||||
}
|
}
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
Id = id;
|
||||||
}
|
}
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -16,11 +18,11 @@ public class User {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
public String getAddress() {
|
public String getMail() {
|
||||||
return address;
|
return mail;
|
||||||
}
|
}
|
||||||
public void setAddress(String address) {
|
public void setMail(String mail) {
|
||||||
this.address = address;
|
this.mail = mail;
|
||||||
}
|
}
|
||||||
public String getPass() {
|
public String getPass() {
|
||||||
return pass;
|
return pass;
|
||||||
@@ -29,5 +31,4 @@ public class User {
|
|||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
|
|
||||||
public class Animal {
|
public class Animal {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public void run() {
|
|
||||||
System.out.println(this.name + "は走りました。");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eat() {
|
|
||||||
System.out.println(this.name + "は食事をしました。");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -18,5 +11,12 @@ public class Animal {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Run() {
|
||||||
|
System.out.println(this.getName()+"走りました。");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Eat() {
|
||||||
|
System.out.println(this.getName()+"は食事をしました。");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
public class Cat extends Animal{
|
public class Cat extends Animal {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,84 @@
|
|||||||
|
|
||||||
public class Character {
|
public class Character {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int power;
|
private int power;
|
||||||
private int defense;
|
private int defense;
|
||||||
|
|
||||||
public Character(int hp, int power, int defense) {
|
|
||||||
this.hp = hp;
|
|
||||||
this.power = power;
|
|
||||||
this.defense = defense;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
public int getHP() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
public void setHP(int HP) {
|
||||||
|
hp = HP;
|
||||||
|
}
|
||||||
|
public int getPower() {
|
||||||
|
return power;
|
||||||
|
}
|
||||||
|
public void setPower(int power) {
|
||||||
|
this.power = power;
|
||||||
|
}
|
||||||
|
public int getDefense() {
|
||||||
|
return defense;
|
||||||
|
}
|
||||||
|
public void setDefense(int defense) {
|
||||||
|
this.defense = defense;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Character() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Character(int HP, int power, int defense) {
|
||||||
|
this.hp = HP;
|
||||||
|
this.power = power;
|
||||||
|
this.defense = defense;
|
||||||
|
}
|
||||||
|
|
||||||
public int attack() {
|
public int attack() {
|
||||||
return this.power;
|
return this.getPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean damage(int enemyAttack) {
|
public boolean dameged(int enemypower) {
|
||||||
int damage = enemyAttack - this.defense; //ダメージ量の計算
|
|
||||||
if(damage <= 0) {
|
boolean isDead = false;
|
||||||
damage = 1; //計算結果が0以下ならダメージ量1にする
|
|
||||||
}
|
int damage = 0;
|
||||||
|
if (enemypower-this.getDefense()<0) {
|
||||||
this.hp -= damage; //hpからダメージ量引いて残りをhpにする
|
damage = 1;
|
||||||
boolean dead= false; //戦闘不能かどうかを真偽地を使って判断
|
} else {
|
||||||
|
damage = enemypower-this.getDefense();
|
||||||
if(this.hp <= 0) { //hpが0以下なら
|
|
||||||
this.hp = 0; //hpを0に補正
|
|
||||||
dead = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(this.name + "は" + damage + "のダメージを受けた");
|
if (this.getHP()-damage<0) {
|
||||||
System.out.println(this.name + "の残りの体力は" + this.hp + "。");
|
this.setHP(0);
|
||||||
|
isDead = true;
|
||||||
if(dead) { //戦闘不能の時
|
} else {
|
||||||
System.out.println(this.name + "はちからつきた。");
|
this.setHP(this.getHP()-damage);
|
||||||
}
|
}
|
||||||
return dead;
|
|
||||||
|
System.out.println(this.getName()+"は"+damage+"のダメージを受けた。");
|
||||||
|
System.out.println(this.getName()+"の残り体力は"+this.getHP()+"。");
|
||||||
|
if(isDead) {
|
||||||
|
System.out.println(this.getName()+"はちからつきた。");
|
||||||
|
}
|
||||||
|
System.out.println("↓");
|
||||||
|
|
||||||
|
return isDead;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String Parameters() { //パラメーターを文字列で返す
|
public String display() {
|
||||||
return "名前:" + this.name + "\n" + "体力:" + this.hp + "\n" +
|
String str = "名 前:"+this.getName()+"\n"
|
||||||
"力" + this.power + "\n" + "耐久" + this.defense;
|
+"体 力:"+this.getHP()+"\n"
|
||||||
|
+" 力 :"+this.getPower()+"\n"
|
||||||
|
+"耐 久:"+this.getDefense();
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
public class Dog extends Animal{
|
public class Dog extends Animal {
|
||||||
public void eat() {
|
public void Eat() {
|
||||||
System.out.println(getName() + "はドッグフードを食べました。");
|
System.out.println(this.getName()+"はドッグフードを食べました。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
public class Hero extends Character{
|
public class Hero extends Character {
|
||||||
public Hero(){
|
public Hero() {
|
||||||
super(25, 10, 7);
|
this.setName("");
|
||||||
|
this.setHP(25);
|
||||||
|
this.setPower(10);
|
||||||
|
this.setDefense(7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,25 @@
|
|||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
private String eName;
|
|
||||||
private int addDamage;
|
|
||||||
|
|
||||||
public Item(String eNmae, int addDamage) {
|
private String name;
|
||||||
this.eName = eNmae;
|
private int add;
|
||||||
this.addDamage = addDamage;
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
public void setName(String name) {
|
||||||
public String geteNmae() {
|
this.name = name;
|
||||||
return eName;
|
|
||||||
}
|
}
|
||||||
|
public int getAdd() {
|
||||||
public void seteNmae(String eNmae) {
|
return add;
|
||||||
this.eName = eNmae;
|
|
||||||
}
|
}
|
||||||
|
public void setAdd(int add) {
|
||||||
public int getAddDamage() {
|
this.add = add;
|
||||||
return addDamage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddDamage(int addDamage) {
|
public Item(String name,int add) {
|
||||||
this.addDamage = addDamage;
|
this.setName(name);
|
||||||
|
this.setAdd(add);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ public class Question13_1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Cat cat = new Cat();
|
Cat cat = new Cat();
|
||||||
cat.setName("タマ");
|
cat.setName("タマ");
|
||||||
cat.run();
|
cat.Run();
|
||||||
cat.eat();
|
cat.Eat();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ public class Question13_2 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
|
||||||
Dog dog = new Dog();
|
Dog dog = new Dog();
|
||||||
dog.setName("ポチ");
|
dog.setName("ポチ");
|
||||||
dog.run();
|
dog.Run();
|
||||||
dog.eat();
|
dog.Eat();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user