日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

java 中文符号占位_java – ‘占位符’字符以避免积极比较?

發布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 中文符号占位_java – ‘占位符’字符以避免积极比较? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在研究CodingBat exercises for Java.我遇到了以下問題:

Given 2 arrays that are the same length containing strings, compare the 1st string in one array to the 1st string in the other array, the 2nd to the 2nd and so on. Count the number of times that the 2 strings are non-empty and start with the same char. The strings may be any length, including 0.

我的代碼是這樣的:

public int matchUp(String[] a, String[] b){

int count = 0;

for (int i = 0; i < a.length; i++) {

String firstLetterA = a[i].length() == 0

? "ê"

: a[i].substring(0, 1);

String firstLetterB = b[i].length() == 0

? "é"

: b[i].substring(0, 1);

if (firstLetterA.equals(firstLetterB)) {

count++;

}

}

return count;

}

我的問題是:哪個“占位符”字符被認為是一種良好的做法,可以避免在firstLetterA和firstLetterB之間進行不必要的比較?

在這種情況下,我只分配了兩個很少使用的不同字母(至少用英文).我嘗試使用”(一個空字符,而不是空格)但當然,它們相互匹配.我也嘗試過使用null,因為我認為它無法進行正面比較,但這也會導致問題.

總結

以上是生活随笔為你收集整理的java 中文符号占位_java – ‘占位符’字符以避免积极比较?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。