09 April 2012

Search for a particular element in Array, in case it is found, exit from loop and display the search result.(Use break)



import java.util.*;
public class Find {
public static void main(String[] args) {
boolean flag = false;
int intArray[]=new int[3];
Scanner input = new Scanner(System.in);
for(int i = 0; i<intArray.length; i++)
{
System.out.println("Enter the number for the array");
intArray[i] = input.nextInt();
}
System.out.println("Array elements are");
for(int i=0; i<intArray.length; i++)
{
System.out.println(intArray[i]);
}
System.out.println("Type the Number For Find the Position");
int n = input.nextInt();
for(int i=0; i<intArray.length; i++)
{
if(n==intArray[i])
{
int j = i+1;
System.out.println("Number found at : "+ j + " "+ " th Coulumn");
flag = true;
break;
}
}
if(flag==false)
System.out.println("Number not found");
}

}


1 comments:

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;