In this program we are searching the particular number inside the array.
First we create a array;
we define a scanner class name sc;
define a boolean variable;
make a integer variable;
decleared the loop and assigned the value of array in ele;
inside the loop defined the if else statement;
when input is equal to arr;
the boolean return the value of true;
and break the statement;
if(a1)// is true return the first sout;
if not true it return false
package com.ritesh;
import javax.security.sasl.SaslClient;
import java.util.Scanner;
public class find_the_array {
public static void main(String[] args) {
int [] arr={ 1,2,55,77,88,33,455,66,33,998,6643,222356};
System.out.println("search the array");
Scanner sc=new Scanner(System.in);
int input=sc.nextInt();
boolean a1=false;
for(int ele:arr)
{
if(input==ele)
{
a1=true;
break;
}
}
if(a1)
{
System.out.printf("You are searching the number ' %d ' avilable is a here",input);
}
else
System.out.printf("the number you are searching '%d' is not avilable here ",input);
}
}
Comments
Post a Comment