
Hi, Can any one please help me to solve below problem.
I have one array i.e. int a[6]={2,3,5,6,7,89}; I have to take an input from user to search for elements present in an array. Suppose user has entered 2 then we have to check whether the next largest is present (for 2 elemnt will be 3,if 3 is present then we have to check 4 is present or not if present then serch for 5). is next elment is not present then we have stop the process and print the result like..
if user enters 2-- then output will be--- 2,3 similary if user enter 5, then o/p will be --5,6,7.

hi friend,
use the following code this may be helpful for you
package roseindia.net;
import java.io.*;
public class SearchElementArray {
public static void main(String args[])
{
int[] arr = {1,2,3,5,6,8,9};
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter number between 1 to 9 : ");
int num = Integer.parseInt(br.readLine());
for(int i=0; i<arr.length; i++)
{
if(arr[i] == num)
{
//num = num+1;
int[] newArr = new int[2];
newArr[0] = num;
for(int j=1; j<newArr.length; j++)
{
newArr[j]=num;
if(arr[i] == newArr[j])
{
num = num+1;
System.out.println(newArr[j]);
}
else
System.out.println(newArr[j]);
}
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}