質問するログイン新規登録

回答編集履歴

3

成形

2017/11/30 15:09

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -28,8 +28,7 @@
28
28
  public class Main {
29
29
  public static void main(String[] args) {
30
30
  int n = 7;
31
-
32
- for(int i=0;i<n;i++) {
31
+ for(int i = 0; i < n; i++) {
33
32
  if(i == 5) {
34
33
  System.out.print("B ");
35
34
  } else {

2

修正

2017/11/30 15:09

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -8,14 +8,14 @@
8
8
  int n = 7;
9
9
 
10
10
  for(int i=0;i<n;i++) {
11
- if(i == 5) {
11
+ if(i == 5) {
12
- Integer oi = new Integer(i);
12
+ Integer oi = new Integer(i);
13
- String str = oi.toString();
13
+ String str = oi.toString();
14
- str = "B";
14
+ str = "B";
15
- System.out.print(str + " ");
15
+ System.out.print(str + " ");
16
- } else {
16
+ } else {
17
- System.out.print(i+ " ");
17
+ System.out.print(i+ " ");
18
- }
18
+ }
19
19
  }
20
20
  }
21
21
  }
@@ -30,12 +30,14 @@
30
30
  int n = 7;
31
31
 
32
32
  for(int i=0;i<n;i++) {
33
- if(i == 5) {
33
+ if(i == 5) {
34
- System.out.print("B ");
34
+ System.out.print("B ");
35
- } else {
35
+ } else {
36
- System.out.print(i+ " ");
36
+ System.out.print(i + " ");
37
- }
37
+ }
38
38
  }
39
39
  }
40
40
  }
41
- ```
41
+ ```
42
+
43
+ ただ出力したいだけなら型を合わせる必要はないです。

1

修正

2017/11/30 15:02

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -1,4 +1,4 @@
1
- 単純に判定まわりの処理が異なるのでは?
1
+ 単純に判定まわりの処理が異なるのでは?排他制御したいのですよね?
2
2
  ```Java
3
3
  import java.util.*;
4
4
 
@@ -19,4 +19,23 @@
19
19
  }
20
20
  }
21
21
  }
22
+ ```
23
+
24
+ 単に、次のように書いてしまっていいようにも思います。
25
+ ```Java
26
+ import java.util.*;
27
+
28
+ public class Main {
29
+ public static void main(String[] args) {
30
+ int n = 7;
31
+
32
+ for(int i=0;i<n;i++) {
33
+ if(i == 5) {
34
+ System.out.print("B ");
35
+ } else {
36
+ System.out.print(i+ " ");
37
+ }
38
+ }
39
+ }
40
+ }
22
41
  ```