回答編集履歴

3

toCharArrayを使った拡張for文に変更

2022/06/15 11:15

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -25,9 +25,9 @@
25
25
  for (int line = 0; line < display.length; line++) {
26
26
  display[line] = "";
27
27
  }
28
- for (int digit = 0; digit < number.length(); digit++) {
28
+ for (char digit: number.toCharArray()) {
29
29
  for (int line = 0; line < display.length; line++) {
30
- display[line] += digits[number.charAt(digit) - '0'][line] + "□";
30
+ display[line] += digits[digit - '0'][line] + "□";
31
31
  }
32
32
  }
33
33
  for (String line: display) {

2

空白調整

2022/06/15 11:05

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -7,16 +7,16 @@
7
7
  public class Main {
8
8
  public static void main(String[] args) throws Exception {
9
9
  String digits[][] = {
10
- {"■■■","■□■", "■□■", "■□■", "■■■"}, // 0
10
+ {"■■■", "■□■", "■□■", "■□■", "■■■"}, // 0
11
- {"□□■","□□■", "□□■", "□□■", "□□■"}, // 1
11
+ {"□□■", "□□■", "□□■", "□□■", "□□■"}, // 1
12
- {"■■■","□□■", "■■■", "■□□", "■■■"}, // 2
12
+ {"■■■", "□□■", "■■■", "■□□", "■■■"}, // 2
13
- {"■■■","□□■", "■■■", "□□■", "■■■"}, // 3
13
+ {"■■■", "□□■", "■■■", "□□■", "■■■"}, // 3
14
- {"■□■","■□■", "■■■", "□□■", "□□■"}, // 4
14
+ {"■□■", "■□■", "■■■", "□□■", "□□■"}, // 4
15
- {"■■■","■□□", "■■■", "□□■", "■■■"}, // 5
15
+ {"■■■", "■□□", "■■■", "□□■", "■■■"}, // 5
16
- {"■□□","■□□", "■■■", "■□■", "■■■"}, // 6
16
+ {"■□□", "■□□", "■■■", "■□■", "■■■"}, // 6
17
- {"■■■","□□■", "□□■", "□□■", "□□■"}, // 7
17
+ {"■■■", "□□■", "□□■", "□□■", "□□■"}, // 7
18
- {"■■■","■□■", "■■■", "■□■", "■■■"}, // 8
18
+ {"■■■", "■□■", "■■■", "■□■", "■■■"}, // 8
19
- {"■■■","■□■", "■■■", "□□■", "□□■"}, // 9
19
+ {"■■■", "■□■", "■■■", "□□■", "□□■"}, // 9
20
20
  };
21
21
 
22
22
  System.out.print("数字を入力:");

1

変数名変更

2022/06/15 11:02

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -22,8 +22,8 @@
22
22
  System.out.print("数字を入力:");
23
23
  String number = new Scanner(System.in).nextLine();
24
24
  String[] display = new String[digits[0].length];
25
- for (int i = 0; i < display.length; i++) {
25
+ for (int line = 0; line < display.length; line++) {
26
- display[i] = "";
26
+ display[line] = "";
27
27
  }
28
28
  for (int digit = 0; digit < number.length(); digit++) {
29
29
  for (int line = 0; line < display.length; line++) {