please answer this question
class 10 in JAVA LANGUAGE write a men driven program (switch case).
no spam
Answers
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int ch,temp=0,min=0,ns=0,lb=0,ub=4;//Initializing loop variables inorder to use both in switch
int a[]=new int[5];
System.out.println("Enter the elements of the array");
for(int i=0;i<5;i++)
{
a[i]=in.nextInt();
}
System.out.println("Enter 1 for bubble sort:");
System.out.println("Enter 2 for selection sort:");
System.out.println("Enter 3 for Binary Search");
System.out.println("Enter 4 for linear search");
System.out.println("Enter your choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
for(int i=0;i<5;i++)
{
for(int j=0;j<5-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("Bubble Sort:"+Arrays.toString(a));
break;
case 2:
for(int i=0;i<4;i++)
{
min=i;
for(int j=i+1;j<5;j++)
{
if(a[j]<a[min])
min=j;
}
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
System.out.println("Selection Sort:"+Arrays.toString(a));
break;
case 3:
int p=0,f=0;
System.out.println("Enter the element to be searched provided that the array is sorted:");
ns=in.nextInt();
while(lb<=ub)
{
p=(lb+ub)/2;
if(a[p]<ns)
lb=p+1;
if(a[p]>ns)
ub=p-1;
if(a[p]==ns)
{
f=1;
break;
}
}
if(f==1)
System.out.println("Search successful the number is present");
else
System.out.println("Search unsuccessful the number is absent");
break;
case 4:
int fr=0;
System.out.println("Enter the number to be searched:");
ns=in.nextInt();
for(int i=0;i<5;i++)
{
if(ns==a[i])
{
fr=1;
break;
}
}
if(fr==1)
System.out.println("Search successful and the number is present");
else
System.out.println("Search unsuccessful and the number is absent");
break;
default:
System.out.println("Invalid Choice");
}
in.close();
}
}
Answer:
I didn't ask you this question
Explanation:
but yeah now l know who is a friend ...
have you seen Harry potter
if you see just tell me
and yeah don't forget to mark me as a brain list