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
base: master
Are you sure you want to change the base?
嶋貫解答(最新) #22
Conversation
public static boolean isPhoneNumber(String s) { | ||
|
||
return false; | ||
return s.matches("[0-9]{3}-?[0-9]{4}-?[0-9]{4}"); |
There was a problem hiding this comment.
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))$"); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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 + " "; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for文内で都度インスタンスを生成することはメモリによろしくないです!
There was a problem hiding this comment.
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 == "府") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これってちゃんと等価されますか?
Javaで文字列の等価を判定する際は .equals
でなければいけません。
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これだと、さらにもう1枚硬貨増えたとき、 8
を書き換えなければいけなくなりませんか?
履歴がおかしくなったので、送りなおします。