عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 18-12-2012, 01:51 AM   #2

الهي رجوتك

جامعي

 
تاريخ التسجيل: Dec 2012
نوع الدراسة: إنتظام
الجنس: أنثى
المشاركات: 2
افتراضي رد: كتابة برنامج بلغه الجافا

نقرتين لعرض الصورة في صفحة مستقلةهذي بداية للحل ..


import javax.swing.JOptionPane ;


publicclass TwoDimTest{

publicstaticvoid main ( String [ ] args )
{
int choice;
String w;
String z;
int sum=0;
int sumdiagonal= 0;
int sumdseconddiagonal= 0;

w = JOptionPane.showInputDialog(
" Enter Row");
z = JOptionPane.showInputDialog(
" Enter column");
int i=Integer.parseInt ( w );
int j=Integer.parseInt ( z );
int[][]malek = newint[i][j];


for (int k=0; k<i; k++)
{
for (int m=0; m<j; m++)
{


String a = JOptionPane.showInputDialog(
" Enter value");
malek[k][m]= Integer.parseInt ( a );
}}

String input = JOptionPane.showInputDialog(
"\t\t\t\t\t"+" Menue \n"+ "Press 1 to Print Array\n"+
"Press 2 to print the sum of Main Diagonal\n"+"Press 3 to print the sum of Secondary Diagonal\n"+ " Press 4 to print the SUM\n"+
"Press 5 to print the MAX\n"+" Press 6 to print the MIN\n"+" Press 7 to do SWAP" ) ;


choice =Integer.parseInt ( input );


if (choice == 1)
{
for (int l=0; l<i; l++)
{
System.out.print (
"\n");

for (int n=0; n<j; n++)
{

System.out.print ( malek[l][n]);

}}
}
else

if (choice == 2)
{
for (int e=0; e<i; e++)
{

for (int f=0; f<j; f++)
{
if (e==f){
sumdiagonal = sumdiagonal + malek[e][f];
}

}
}
System.out.print (
" The sum of Main Diagonal =" + sumdiagonal);


}
else
if
(choice == 3)
{
for (int p=0; p<i; p++)
{

for (int q=0; q<j; q++)
{
if (p+q == i-1){
sumdseconddiagonal = sumdseconddiagonal + malek[p][q];
}

}
}
System.out.print (
" The sum of Secondary Diagonal =" + sumdseconddiagonal);


}
else


if
(choice == 4)
{
for (int b=0; b<i; b++)
{
System.out.print (
"\n");

for (int c=0; c<j; c++)
{
sum = sum + malek[b][c];


}}
System.out.print (
" The sum of array =" + sum);
}


System.exit ( 0 ) ;
}
}

 

الهي رجوتك غير متواجد حالياً   رد مع اقتباس