Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

嶋貫解答(最新) #22

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

tatsuru-shimanuki
Copy link
Collaborator

履歴がおかしくなったので、送りなおします。

public static boolean isPhoneNumber(String s) {

return false;
return s.matches("[0-9]{3}-?[0-9]{4}-?[0-9]{4}");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これって、東京03の場合falseになっちゃいませんかね?

}

public static boolean isMailAddress(String s) {

return false;
return s.matches(".+@.+((\\.com)|(\\.co.jp)|(\\.ne.jp))$");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これって、.cojp とか .conjp とかがtrueになっちゃいませんかね?
nejpも同様。


Random ransu = new Random();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これが実は先日ちらっと話した「ループ内で変数作るとメモリに悪い問題」です!

case 2:
pa += 1;
break;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ロジック上到達することないですが、case が 3だったらどうなるでしょうねえ。
case default というキーワードで調べてみてください!

if (n == 1) {
y = y + x;
} else {
y = y + x + " ";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

忘れた頃に +=


long start = System.nanoTime();
for (int j = 0; j <= 100000; j++) {
Random r = new Random();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for文内で都度インスタンスを生成することはメモリによろしくないです!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

学んだことを活かせてませんでした。


List<String> list = new ArrayList<String>();

if (n == "県" || n == "都" || n == "道" || n == "府") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これってちゃんと等価されますか?
Javaで文字列の等価を判定する際は .equals でなければいけません。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等価判定ができてなかったですね。
リストの当道府県と、 if (ken.endsWith(n)) { の部分で弾かれていたので、できているように見えていたようです。


return list.stream()
.filter(i -> i.endsWith(n))
.collect(toList());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よき!

Practice027.fruitsList().stream()
.max(Comparator.comparingInt(p -> p.getPrice()))
.map(p -> p.getJapanName())
.get();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都度streamで商品拾ってきますが、
一度最高金額のFruitsを取得してしまえば、あと楽に書けませんかね?

}
//コインの種類
int[] coin = {500, 250, 100, 50, 25, 10, 5, 1};
int[] coinNumber = new int[8];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これだと、さらにもう1枚硬貨増えたとき、 8 を書き換えなければいけなくなりませんか?

@Kotanin0 Kotanin0 added the 要リファクタ ⛔ リファクタリングをしてください label Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
小谷レビュー済:cyclone: 要リファクタ ⛔ リファクタリングをしてください
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants