优美的代码赏析

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");
	}
	
	}
}

猜你喜欢

转载自blog.csdn.net/WU_SIMON_SJTU/article/details/109367820