回答編集履歴

4

隠蔽

2018/04/24 06:58

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -3,63 +3,3 @@
3
3
  1. キャピタライズは面倒臭いので**Apache Commons Text**の[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使う。
4
4
 
5
5
  1. String.formatで整形。
6
-
7
-
8
-
9
- ---
10
-
11
-
12
-
13
- ```java
14
-
15
- String lines[] = {
16
-
17
- "apple 100 5",
18
-
19
- "banana 30 10",
20
-
21
- "curry rice 500 1",
22
-
23
- };
24
-
25
- for (String line: lines) {
26
-
27
- //分割
28
-
29
- String[] splitted = line.split(" ", 0);
30
-
31
- int length = splitted.length;
32
-
33
-
34
-
35
- //名前
36
-
37
- String name = String.join(" ", Arrays.copyOfRange(splitted, 0, length-2));
38
-
39
- /* キャピタライズは省略 */
40
-
41
- //数量
42
-
43
- int quantity = Integer.parseInt(splitted[length-1]);
44
-
45
- //単価
46
-
47
- int price = Integer.parseInt(splitted[length-2]);
48
-
49
-
50
-
51
- //整形
52
-
53
- String formatted = String.format("%-10s %6s %6d %7d", name, "$"+(double)price, quantity, price*quantity);
54
-
55
- System.out.println(formatted);
56
-
57
- }
58
-
59
- //=> apple $100.0 5 500
60
-
61
- //=> banana $30.0 10 300
62
-
63
- //=> curry rice $500.0 1 500
64
-
65
- ```

3

丸投げ

2018/04/24 06:58

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -3,3 +3,63 @@
3
3
  1. キャピタライズは面倒臭いので**Apache Commons Text**の[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使う。
4
4
 
5
5
  1. String.formatで整形。
6
+
7
+
8
+
9
+ ---
10
+
11
+
12
+
13
+ ```java
14
+
15
+ String lines[] = {
16
+
17
+ "apple 100 5",
18
+
19
+ "banana 30 10",
20
+
21
+ "curry rice 500 1",
22
+
23
+ };
24
+
25
+ for (String line: lines) {
26
+
27
+ //分割
28
+
29
+ String[] splitted = line.split(" ", 0);
30
+
31
+ int length = splitted.length;
32
+
33
+
34
+
35
+ //名前
36
+
37
+ String name = String.join(" ", Arrays.copyOfRange(splitted, 0, length-2));
38
+
39
+ /* キャピタライズは省略 */
40
+
41
+ //数量
42
+
43
+ int quantity = Integer.parseInt(splitted[length-1]);
44
+
45
+ //単価
46
+
47
+ int price = Integer.parseInt(splitted[length-2]);
48
+
49
+
50
+
51
+ //整形
52
+
53
+ String formatted = String.format("%-10s %6s %6d %7d", name, "$"+(double)price, quantity, price*quantity);
54
+
55
+ System.out.println(formatted);
56
+
57
+ }
58
+
59
+ //=> apple $100.0 5 500
60
+
61
+ //=> banana $30.0 10 300
62
+
63
+ //=> curry rice $500.0 1 500
64
+
65
+ ```

2

こっそりリンク修正。

2018/04/24 06:57

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -1,5 +1,5 @@
1
1
  1. String.splitで分割。
2
2
 
3
- 1. キャピタライズは面倒臭いので**Apache Commons Text**の[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-1.2/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使う。
3
+ 1. キャピタライズは面倒臭いので**Apache Commons Text**の[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使う。
4
4
 
5
5
  1. String.formatで整形。

1

順番。

2018/04/24 06:32

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -1,5 +1,5 @@
1
1
  1. String.splitで分割。
2
2
 
3
+ 1. キャピタライズは面倒臭いので**Apache Commons Text**の[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-1.2/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使う。
4
+
3
5
  1. String.formatで整形。
4
-
5
- 1. キャピタライズは面倒臭いので、Apache Commons Textの[WordUtilsクラス](https://commons.apache.org/proper/commons-text/javadocs/api-1.2/org/apache/commons/text/WordUtils.html)のキャピタライズ関連のメソッドを使うのが簡単かと。