package lord1;
import javax.swing.JOptionPane;
public class arraydelete {
public static void main(String[]args)
{
String[][] arr = new String[5][2];
String choice=" ";
String container="";
String element="";
String sumpay="";
do{
choice=JOptionPane.showInputDialog(null,"V--->View element \nD--->Delete element \nI--->Insert element \nE--->Exit");
choice=choice.toUpperCase();
//view element
if(choice.equals("V")==true)
{
sumpay="";
for(int column=0;column<5;column++)
{
for(int row=0;row<2;row++)
{
sumpay+= " "+ arr[column][row];
}
}
JOptionPane.showMessageDialog(null, "Array element " + sumpay);
}
//delete element
if(choice.equals("D")==true)
{
int empty=0;
int notempty=0;
element=JOptionPane.showInputDialog(null,"Enter element");
for(int column=0;column<5;column++)
{
for(int row=0;row<2;row++)
{
if(arr[column][row]!=null)
{
if(arr[column][row].equals(element)==true)
{
arr[column][row]=null;
notempty=1;
}
}
else
{
empty=1;
}
}
}
if(empty==0 && notempty==1)
{
JOptionPane.showMessageDialog(null, "value is deleted");
notempty=0;
}
if(empty==1 && notempty==0)
{
JOptionPane.showMessageDialog(null, "Element is not on the list to delete");
empty=0;
}
}
//insert element
if(choice.equals("I")==true)
{
for(int column=0;column<5;column++)
{
for(int row=0;row<2;row++)
{
container=JOptionPane.showInputDialog(null,"Maximum value is 10" + "\nColumn [" + column + "]" + "Row [" + row + "]" +" Insert element");
if(arr[column][row]!=null)
{
if(arr[column][row].equals(container)==true)
{
JOptionPane.showMessageDialog(null, "Already exists");
}
else
{
JOptionPane.showMessageDialog(null, "occupied");
}
}
else
{
arr[column][row]=container;
}
}//first for
}//first for
}
}
while(choice.equals("E")==false);
JOptionPane.showMessageDialog(null, "System terminated");
}
}
No comments:
Post a Comment