JAVA程式語言設計(第三版)
這段程式相當的優美:
1,命名法則采用駝峰法則,小寫開頭大寫后續每個單詞的首字母
2,沒有直接去尋找12,而是把12付給一個變數,代碼修改起來方便,
3,輸出沒有直接在判斷邏輯的IF回圈里面輸出,而是用了一個布朗型的資料,利用輸出段輸出,
可讀性好,修改操作方便,定義區,計算區和輸出區域分模塊編程,
美不勝收,
public class text{
public static void main(String args[]) {
int[] arrayOfInts= {32,87,3,589,12,1076,2000,8,622,127};
int searchFor=12;
int i=0;
boolean foundIt=false;
for(;i<arrayOfInts.length;i++) {
if(arrayOfInts[i]==searchFor)
{foundIt=true;
break;
}
}
if(foundIt) {
System.out.println("Found "+searchFor+" at index"+i);
}else {
System.out.println(searchFor+"not in the array");
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/196493.html
標籤:其他
