Design a program to create an array of integers, size should be entered by the user(between 5 to 20). And search a number by linear search technique. If the value is not found then print relevant message.

import java.util.*;
class Q4
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the size of array between 5 to 20");
        int n=sc.nextInt();
        String list[]=new String[n];
        int len=list.length;
        for(int i=0;i<len-1;i++)
        {
            for(int j=0;j<len-1-i;j++)
            {
                if((list[j].compareTo(list[j+1]))>0)
                {
                    String temp=list[j];
                    list[j]=list[j+1];
                    list[j+1]=temp;
                }
            }
        }
        System.out.println("Sorted array");
        for(int i=0;i<len;i++)
        {
            System.out.println(list[i]);
        }
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here