質問編集履歴
1
インデントど
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,60 +14,60 @@
|
|
14
14
|
### 変数と配列の宣言と出力
|
15
15
|
```ここに言語を入力
|
16
16
|
class Main {
|
17
|
-
public static void main(String[] args) {
|
17
|
+
public static void main(String[] args) {
|
18
|
-
String a = "hello world";
|
18
|
+
String a = "hello world";
|
19
|
-
int b = 1;
|
19
|
+
int b = 1;
|
20
|
-
String bar[] = new String[2];
|
20
|
+
String bar[] = new String[2];
|
21
|
-
bar[0] = "bar1";
|
21
|
+
bar[0] = "bar1";
|
22
|
-
bar[1] = "bar2";
|
22
|
+
bar[1] = "bar2";
|
23
23
|
|
24
|
-
System.out.println("aには"+ a);
|
24
|
+
System.out.println("aには"+ a);
|
25
|
-
System.out.println("bには"+ b);
|
25
|
+
System.out.println("bには"+ b);
|
26
26
|
|
27
|
-
System.out.println(bar[0]);
|
27
|
+
System.out.println(bar[0]);
|
28
|
-
System.out.println(bar[1]);
|
28
|
+
System.out.println(bar[1]);
|
29
|
+
}
|
29
30
|
}
|
30
|
-
}
|
31
31
|
```
|
32
32
|
### メソッド(RPGでは、処理を分けたもののことをサブルーチンと聞きます)
|
33
33
|
```ここに言語を入力
|
34
34
|
class Main {
|
35
|
-
public static void main(String args[]){
|
35
|
+
public static void main(String args[]){
|
36
|
-
hoge(1, 3, "!");
|
36
|
+
hoge(1, 3, "!");
|
37
|
-
}
|
37
|
+
}
|
38
38
|
|
39
|
-
public static void hoge(int a, int b, String c){
|
39
|
+
public static void hoge(int a, int b, String c){
|
40
|
-
System.out.println(a + b + "です"+ c);
|
40
|
+
System.out.println(a + b + "です"+ c);
|
41
|
+
}
|
41
42
|
}
|
42
|
-
}
|
43
43
|
```
|
44
44
|
### 入力と、if文
|
45
45
|
```ここに言語を入力
|
46
46
|
import java.util.Scanner;
|
47
47
|
class Main {
|
48
|
-
public static void main(String[] args) {
|
48
|
+
public static void main(String[] args) {
|
49
|
-
System.out.println("キーボードから入力してください");
|
49
|
+
System.out.println("キーボードから入力してください");
|
50
50
|
|
51
|
-
Scanner scan = new Scanner(System.in);
|
51
|
+
Scanner scan = new Scanner(System.in);
|
52
|
-
String str = scan.next();
|
52
|
+
String str = scan.next();
|
53
53
|
|
54
|
-
if(str.equa("朝")) {
|
54
|
+
if(str.equa("朝")) {
|
55
|
-
System.out.println("
|
55
|
+
System.out.println("おはよう");
|
56
|
-
} else if(str.equa("夜")) {
|
56
|
+
} else if(str.equa("夜")) {
|
57
|
-
System.out.println("こんばんは");
|
57
|
+
System.out.println("こんばんは");
|
58
|
-
} else {
|
58
|
+
} else {
|
59
|
-
System.out.println("朝か夜を入力してね");
|
59
|
+
System.out.println("朝か夜を入力してね");
|
60
|
+
}
|
61
|
+
}
|
60
62
|
}
|
61
|
-
}
|
62
|
-
}
|
63
63
|
```
|
64
64
|
### for文
|
65
65
|
```ここに言語を入力
|
66
66
|
class Main {
|
67
|
-
public static void main(String[] args) {
|
67
|
+
public static void main(String[] args) {
|
68
|
-
for (int i = 0; i <10; i++) {
|
68
|
+
for (int i = 0; i <10; i++) {
|
69
|
-
System.out.println(i);
|
69
|
+
System.out.println(i);
|
70
|
+
}
|
71
|
+
}
|
70
72
|
}
|
71
|
-
}
|
72
|
-
}
|
73
73
|
```
|