package lord1;
import javax.swing.JOptionPane;
public class searchelement {
public static void main(String[]args)
{
int display=0;
String x="",xx="";
String y="",yy="";
double container=0;
x=JOptionPane.showInputDialog(null,"Enter Size of Array:\nEnter column\n");
y=JOptionPane.showInputDialog (null," Rows");
int c=Integer.parseInt(x);
int r=Integer.parseInt(y);
Integer arr [][]=new Integer [c][r];
for(int f=0;f<c;f++)
{
for(int g=0;g<r;g++)
{
String user=JOptionPane.showInputDialog(null,"Enter element");
int user1=Integer.parseInt(user);
arr[f][g]=user1;
}
}
xx=JOptionPane.showInputDialog(null,"Search Value");
int cc=Integer.parseInt(xx);
int ff=0,gg=0;
for( ff=0;ff<c;ff++)
{
for( gg=0;gg<r;gg++)
{
if(arr[ff][gg]==cc)
{
container=arr[ff][gg];
JOptionPane.showMessageDialog(null,"The Values is : " + container + " Location "+ "["+ ff + " ]" + " " + "["+ gg + " ]" );
break;
}
}
}
if(container==0)
{
JOptionPane.showMessageDialog(null, "Not found in the list ");
}
}
}
No comments:
Post a Comment