السلام عليكم ورحمة الله وبركاته
public class Arrays{
public static void main(String args[]){
int x[]=new int[5];
String a;
int h=1;
while(h!=0)
{
a= JOptionPane.showInputDialog("\t Select any Number:\n\n"+"\t 1:- Insert\n"+"\t 2:- Delete\n"+"\t 3:- ADD\n"+
"\t4:-Search\n"+"\t 5:-Sort\n"+"\t 5:- Dispaly\n");
h = Integer.parseInt( a );
switch(h)
{
case 1: insert(x);
break;
case 2: sort(x);
break;
case 3: Delete(x);
break;
case 4: Search(x);
break;
// case 5: Add(x);
// break;
case 6: Display(x);
break;
}//end switch
}//end while
System.exit(0);
}//end main()
//--------------------------Insert()------------------------------
static void insert(int x[])
{
int i;
String s;
{
for(i=0;i<x.length;i++)
{
s= JOptionPane.showInputDialog("Enter The Array:");
x = Integer.parseInt( s );
}
}
}
//------------------------------Sort()---------------------------------
static void sort(int x[])
{
int temp;
int i;
for(i=0;i<x.length-1;i++){
for(int j=i+1;j<x.length;j++){
if(x>x[j])
{
temp=x;
x=x[j];
x[j]=temp;
}
}
}
}
//----------------------------------Delete------------------------------------
static boolean Delete(int x[])
{
int i,m,L=0;
String j;
j= JOptionPane.showInputDialog("Enter The Delete:");
m= Integer.parseInt( j );
for (int k=0;k<x.length;k++){
if(x[k]==m) {
if(k!=x.length-1){
for (i=k;i<x.length-1;i++)
x=x[i+1];
x[x.length-1]=0;
L=1;
}
}
if(L==1)
return true;
else
return false;
}
}
//-----------------------------Search()---------------------------------
static void Search(int x[])
{
int z,L=0;
String r;
r= JOptionPane.showInputDialog("Enter The Delete:");
z= Integer.parseInt( r );
String f="The Found";
for (int i=0;i<x.length;i++){
if(z==x) {
L=1;
f+=i+"\n";
break;
}
}
if(L==1)
JOptionPane.showMessageDialog(null,f,"Search",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,"I Is Not Foundt","Search",JOptionPane.INFORMATION_MESSAGE);
}
//-------------------------------------ADD()-------------------------------------------
/*static void Add(int k)
{
int z,w;
String r;
for (z=1;z<xlenght;z++){
if(x[z]==0)
{
x[z]=k;
w=0;
break;
}
else
w=1;
if(w==1)
System.out.println("Error Not Found Alpcation"+"\n");
}
}
*/
//-------------------------Display----------------------------
static void Display(int x[]){
String g=" ";
for (int j=0;j<x.length;j++) // display items
g+=""+x[j]+"\n";
JOptionPane.showMessageDialog(null,g,"The Dispaly",JOptionPane.INFORMATION_MESSAGE);
}
}//end class
import javax.swing.*;
جزاكم الله حير
انتظر ردودكم
