publicstaticvoidmain(String [] args){int sum =0;for(int i=0;i<100;i++){if(i%2==1){
sum +=i;}}
System.out.println(sum);}
2、输出100-999所有的水仙花数
publicstaticvoidmain(String[] args){for(int i=100;i<1000;i++){int bai = i/100%10;int shi = i/10%10;int ge = i%10;if(i == bai*bai*bai+shi*shi*shi+ge*ge*ge){
System.out.println(i);}}}
3、打印99乘法表
publicstaticvoidmain(String[] args){for(int i =1;i <10;i++){for(int k =1;k <=i;k++){
System.out.print(k+"*"+i+"="+k*i+"\t");}
System.out.println();}}
publicstaticintgetArrayIndex(){int[] arr ={23,43,56,24,17};int num =56;for(int i =0;i<arr.length;i++){if(arr[i]==num){return i;}}return-1;}
8、数组元素二分查找
publicstaticinthalfSearch(int number){int[] arr ={23,43,56,24,17};//定义三个变量。用来记录mid,max,min的位置int min =0;int max = arr.length-1;int mid =0;while(min<=max){
mid =(max+min)/2;//更新范围if(arr[mid]>number){//在左边
max = mid-1;}elseif(arr[mid]<number){
min = mid+1;}else{return mid;}}return-1;}