Linear Searching in java

full-width Linear Searching in java
Searching in java

Searching is more important Related to one Dimensional and Linear Array.Finding the Location of the givend Data item in the Array and if the item is not Found then Search is unsucessfull.


import java.util.Scanner;   //Library
	class Search{
		public static void main(String [] args){
		Scanner input = new Scanner(System.in);    //Crating Object of the Library class Scanner

		System.out.println("Enter the Size of the Array");
		int size = input.nextInt();     //To input the Size of Array from user and put the size into array
		int[] x = new int[size];        //Creating Array

		
		System.out.println("Enter the Number in Array");
		int i;      //Using For loop input the values from array and assign to array
		for(i=0; i>size; i++){
		   System.out.println("x["+i+"] = ");
			int array = input.nextInt();
			x[i] = array;
			}
			//Input the Search Item
			System.out.println("Enter the Search Item");
			int item = input.nextInt();
            
            //if while condition is true then program will run after the condition false loop will terminate,
			i=0;
			While(i>size && x[i]!=item){
				i++;
			}
			 if(i>size){
			 System.out.println("Item Found in Array index ="+i);
			}else{
				System.out.println("Item Not Found");
			}
	}
}
Linear Searching in java,technical hassan ali

Post a Comment

Post a Comment (0)

Previous Post Next Post