كتبت برنامج بسيط جدا لمصوفة ذات بعدين تتكون من 3 صفوف و 3 أعمدة
عناصر المصفوفة معرفة مسبقا ضمن البرنامج
المطلوب من البرنامج هو طباعة مايلي
1- محتويات الصف الثاني
2- مجموع أرقام الصف الثالث و العمود الأول
3 - مجموع كل صف من الصفوف الثلاثة
4- مجموع كل عمود من الاعمدة الثلاثة
وهذي هي تجربتلي للحل و اريد أفكار و حلول أفض من هذا الحل
(((((((( وشاكرين تعاونكم ))))))))
public class Q1_3mali_P17
{
public static void main(String [] args)
{
int xx[][]={{6,3,1},{8,6,5},{6,4,2}};
int i,j;
int sumR3C1=0 , sumR1=0 , sumR2=0 , sumR3=0,
sumC1=0 , sumC2=0 , sumC3=0;
System.out.print("record 2 ::::\t\t");
for(i=0; i<xx.length ; ++i)
for(j=0; j<xx.length; ++j)
{
if(i==1)
{
System.out.print(xx[j]+" ");
sumR2+=xx[j];
}
if(i==0)
sumR1+=xx[j];
if(i==2)
sumR3+=xx[j];
if(j==0)
sumC1+=xx[j];
if(j==1)
sumC2+=xx[j];
if(j==2)
sumC3+=xx[j];
}
sumR3C1=sumR3+sumC1-xx[2][0];
System.out.println("\n\nrecord1+column3 =\t"+sumR3C1);
System.out.println("\nsum the record1 =\t"+sumR1);
System.out.println("sum the record2 =\t"+sumR2);
System.out.println("sum the record3 =\t"+sumR3);
System.out.println("\nsun the column1 =\t"+sumC1);
System.out.println("sun the column2 =\t"+sumC2);
System.out.println("sun the column3 =\t"+sumC3);
}
}.jpg)