zoukankan      html  css  js  c++  java
  • 数组逆序输出与简单的数据匹配

      简单数据匹配就是给出一个数字,在数组中查找该数字是否存在于数组当中(要考虑到查找到了就不用继续查找了,用break)。

    public class ArryTest {
    
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    int arry[] = new int[] {10,20,3,0,5};
    int search = 3;
    boolean temp = false;
    for(int i=0 ;i<arry.length; i++) {
    	if(arry[i] == search) {
    		temp = true;
    		break;
    	}
    }
    System.out.println(temp ? "找到相同数据" : "么有找到");
    	}
    
    }
     
    

      数组的逆序输出:应该考虑到奇数个元素与偶数个元素的问题。

    public class TestArry {
    
        public static void main(String[] args) {
    int Arry [] =new int[] {1,2,3,4,5,6};
    int head = 0;             //计算头部索引
    int tail = Arry.length-1;       //计算尾部索引
    for(int i=0; i<Arry.length/2; i++) {     //控制循环次数
        int temp = Arry[tail];
        Arry[tail] = Arry[head];
        Arry[head] = temp;
        head++;
        tail--;
    }
    for(int j=0;j<Arry.length;j++) {
        System.out.println(Arry[j]);
    }
        }
    
    }
  • 相关阅读:
    Swift
    ios高质量博客
    Swift
    UML建模
    Swift
    Swift
    IIS建立.net framework4 应用程序池HTTP 错误 500.21
    zz entity framework vs linq to sql
    zz部署wcf iis
    zzIIS站点中部署WCF项目
  • 原文地址:https://www.cnblogs.com/128-cdy/p/11269372.html
Copyright © 2011-2022 走看看