Write a Java program that will incorporate either a sequenti

Write a Java program that will incorporate either a sequential search method or a sort method

Solution

class Search

{

public static void main(String args[])

{ int array[],n;

System.out.println(\"Please enter the sixe of array\");

Scanner s = new Scanner(System.in);

int n = s.nextInt();

System.out.println(\"Please enter\"+ n +\"elements of array\");

for(int i= 0;i<n;i++)

{

array[i]= s.nextInt();

}

System.out.println(\"Please enter your choice 1. Sequential search 2.Sort\");

int choice = s.nextInt();

switch(choice)

{

case 1:

System.out.println(\"Please enter the element to be searched\");

int element = s.nextInt();

for(int i =0;i<n;i++)

{

if(array[i]==element)\\

{

Syste,.out.println(\"Element found at index\" +i);

break;

}

}

break;

case 2:

int temp;

for(int i = 0;i<n;i++)

{

for(j= i+1 ;j<n;j++)

{

temp = array[i];

array[i]= array[j];

array[j]=temp;

}

}

System.out.println(\"Array in ascending order\");

for(i=0;i<n;i++)

{

System.out.println(array[i]);

}

}

}

}

Write a Java program that will incorporate either a sequential search method or a sort methodSolutionclass Search { public static void main(String args[]) { int

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site