Home >Java >javaTutorial >How to implement linear search in java

How to implement linear search in java

WBOY
WBOYforward
2023-04-24 18:28:15919browse

Linear Search

public class T05 {
    public static void main(String[] args) {
        int[]arr=new int[]{1,2,3,4,5,6,7,8,9};
        for(int i=0;i< arr.length;i++){
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
        for(int i=0;i< arr.length;i++){
            if(i< arr.length-1-i){
                int a=arr[i];
                arr[i]=arr[arr.length-1-i];
                arr[arr.length-1-i]=a;
            }
        }
        for(int i=0;i< arr.length;i++){
            System.out.print(arr[i]+"\t");
        }
    }
}

How to implement linear search in java

How to implement linear search in java

The above is the detailed content of How to implement linear search in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete