الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[ تنبيه ] بليز مساعده في طباعة الmatrix بشكل صحيح!

بدأه *en* في 7 نوفمبر 2010 · 12 رد · 583 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

import java.util.Scanner;



public class gradesofstudent {



 


public static void finalGrades( double course[][], double total[]){



total[5]=0.0;





System.out.println ("the total grades for each student: ");


for (int row = 0 ; row < course.length;row++){



for (int column = 0 ; row < course[row].length; column ++){



if (row == 0)


{


total [0] += course[0][column];


System.out.print("student 5: ");


System.out.print(total[0]);



}



if (row == 1)


{


total [1] += course[1][column];


System.out.print("student 2: ");


System.out.print(total[1]);



}


if (row == 2)


{


total [2] += course[2][column];


System.out.print("student 3: ");


System.out.print(total[2]);



}


if (row == 3)


{


total [3] += course[3][column];


System.out.print("student 4: ");


System.out.print(total[3]);



}


if (row == 4)


{


total [4] += course[4][column];


System.out.print("student 5: ");


System.out.print(total[4]);


}


}



}





}





public static void main(String[] args) {




double sum[] ;


sum = new double[5];




double studentGrade[][];


studentGrade = new double[5][4];



System.out.println("Enter the gradesof the 5x4 array : ");



Scanner input = new Scanner(System.in);



for (int row = 0 ; row < studentGrade.length;row++){



for (int column = 0 ; row < studentGrade[row].length; column ++)



studentGrade[row][column]= input.nextDouble();





}



 


gradesofstudent Garde = new gradesofstudent();



Garde . finalGrades( studentGrade , sum);



 


}


}



/*


Enter the gradesof the 5x4 array :


23.5 21 8.5 35.6


17.5 0 6.7 29


Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4


at gradesofstudent.main(gradesofstudent.java:80)


*/

العفو بس موهذا الكود اللي كتبته ماادري شفيه علق ماقااااااااااعد يطلع الكووووود بالموضوع

import java.util.Scanner;



public class gradesofstudent {



 


public static void finalGrades( double course[][], double total[]){



total[5]=0.0;





System.out.println ("the total grades for each student: ");


for (int row = 0 ; row < course.length;row++){



for (int column = 0 ; row < course[row].length; column ++){



if (row == 0)


{


total [0] += course[0][column];


System.out.print("student 5: ");


System.out.print(total[0]);



}



if (row == 1)


{


total [1] += course[1][column];


System.out.print("student 2: ");


System.out.print(total[1]);



}


if (row == 2)


{


total [2] += course[2][column];


System.out.print("student 3: ");


System.out.print(total[2]);



}


if (row == 3)


{


total [3] += course[3][column];


System.out.print("student 4: ");


System.out.print(total[3]);



}


if (row == 4)


{


total [4] += course[4][column];


System.out.print("student 5: ");


System.out.print(total[4]);


}


}



}





}



:mad:وللليه هذا صج معلق

import java.util.Scanner;

public class gradesofstudent {

 

public static void finalGrades( double course[][], double total[]){

total[5]=0.0;

System.out.println ("the total grades for each student: ");

for (int row = 0 ; row < course.length;row++){

for (int column = 0 ; row < course[row].length; column ++){

if (row == 0)

{

total [0] += course[0][column];

System.out.print("student 5: ");

System.out.print(total[0]);

}

if (row == 1)

{

total [1] += course[1][column];

System.out.print("student 2: ");

System.out.print(total[1]);

}

if (row == 2)

{

total [2] += course[2][column];

System.out.print("student 3: ");

System.out.print(total[2]);

}

if (row == 3)

{

total [3] += course[3][column];

System.out.print("student 4: ");

System.out.print(total[3]);

}

if (row == 4)

{

total [4] += course[4][column];

System.out.print("student 5: ");

System.out.print(total[4]);

}

}

}

}

public static void main(String[] args) {

double sum[] ;

sum = new double[5];

double studentGrade[][];

studentGrade = new double[5][4];

System.out.println("Enter the gradesof the 5x4 array : ");

Scanner input = new Scanner(System.in);

for (int row = 0 ; row < studentGrade.length;row++){

for (int column = 0 ; row < studentGrade[row].length; column ++)

studentGrade[row][column]= input.nextDouble();

}

 

gradesofstudent Garde = new gradesofstudent();

Garde . finalGrades( studentGrade , sum);

 

}

}

/*

Enter the gradesof the 5x4 array :

23.5 21 8.5 35.6

17.5 0 6.7 29

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4

at gradesofstudent.main(gradesofstudent.java:80)

*/

:wacko:سووووري إذا الكووووووووود مووااضح بس حاااولت مايطلع

تم تعديل هذه المشاركة بواسطة *en* في 7 نوفمبر 2010 في 12:43

#2

الخطأ متكرر مرتين :

for (int column = 0 ; row < studentGrade[row].length; column ++)

يجب أن يكون

for (int column = 0 ; cloumn< studentGrade[row].length; column ++)

تم تعديل هذه المشاركة بواسطة aohammed في 7 نوفمبر 2010 في 13:40

#3

*- يحظر استخدام اللهجة العامية

*- أو كتابة الأسئلة باللغة الإنجليزية

*- أو كتابة الكلمات الإنجليزية بالعربية

====

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#4

زى ما الاخ الكريم قالك ان عندك خطا

for (int column = 0 ; row < studentGrade[row].length; column ++)

وكان عندك تكرار كتير فى الكود

وانا عدلت الكود بناء على اللى فهمته من اللى عاوزه تعمليه

وهذا هو الكود بعد التعديل

/**
 *
 * @author Mahmoud Kelany
 */
import java.util.Scanner;

public class GradesOfStudent {

	public static void finalGrades(double course[][], double total[]) {
    	total[total.length - 1] = 0.0;
    	System.out.println("the total grades for each student: ");

    	for (int row = 0; row < course.length; row++) {
        	for (int column = 0; column < course[column].length; column++) {

            	total[row] += course[row][column];
            	if (row == 0) {
                	System.out.print("student 5:  ");
            	} else {
                	System.out.print("student " + (row + 1) + ":  ");
            	}
            	System.out.println(total[row]);
        	}
    	}
	}

	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	int rowCount = 5;
    	int colCount = 4;

    	double sum[] = new double[rowCount];
    	double studentGrade[][] = new double[rowCount][colCount];
    	System.out.println("Enter the gradesof the 5x4 array : ");

    	for (int row = 0; row < studentGrade.length; row++) {
        	for (int column = 0; column < studentGrade[0].length; column++) {
            	studentGrade[row][column] = input.nextDouble();
        	}
    	}
    	finalGrades(studentGrade, sum);
	}
}

Software Developer
Mahmoudkelany.com


 

#5

صراااااااحه يعطيكم العااافيه بس آنا بفهم ليش الإدااااره أو المشرفين حااااااااطين تنبه اشدعوووه ماسويت شي قاااعد اطبق القانون وحاااااطه الكود بس عشااااان انه علق وطلع بهلمنظر ماعلينا اأخي الكريم ماتقصر آنا ادري اني ماحطيت السؤال وكووودك ماشاء الله صح بس مو نفس اللي أبيه سويت كووودك وحاولت اعدل فيه بس قاااااعد يتكرر توتل كل طالب وأرقام ماتنجمع !!

لمن سويت الكود مالك طلع جذي

وأنا ماأبيه بهطريقه

الoutput

Enter the gradesof the 5x4 array :

23.5 21 8.5 35.6

17.5 0 6.7 29

8.7 12.5 9.9 37

25 24 0 10

9 11.5 0 10

the total grades for each student:

student 1: 23.5

student 1: 44.5

student 1: 53.0

student 1: 88.6

student 2: 17.5

student 2: 17.5

student 2: 24.2

student 2: 53.2

student 3: 8.7

student 3: 21.2

student 3: 31.1

student 3: 68.1

student 4: 25.0

student 4: 49.0

student 4: 49.0

student 4: 59.0

student 5: 9.0

student 5: 20.5

student 5: 20.5

student 5: 30.5

هذا السؤال مع outputالمطلوبه عشاااااان وااااااضحه معااااااك

Write a java program that reads from the user the grades of five students, and stores the values

in a two dimensional array Course, where each column in array Course represents the grade of

Midterm 1 (25%) , Midterm 2 (25%), Homework (10%) and Final exam (40%), respectively. Write a

method called finalGrades that finds the total grades of each student and stores the result in a one

dimensional array Total. The method should receive the two arrays: Course, and Total, as follows:

public static void finalGrades(double Course[][], double Total[])

At the end, the program should print the total grade of each student. (Print the content of array total

in main method).

Sample output

Enter the values of the 5x4 array

23.5 21 8.5 35.6

17.5 0 6.7 29

8.7 12.5 4 18.6

25 24 9.9 37

9 11.5 0 10

3

Kuwait University College of Engineering

The total grades for each student:

Student 1: 88.60

Student 2: 53.20

Student 3: 43.80

Student 4: 95.90

Student 5: 30.50

أسفه ماشفت التعلييق اللي كاتبه المشرف

بس عشاان هذا

حسناً سنغير الطريقه لكيلا تعصبووو :mellow:

#6

التعديل كان فى الfor المسئوله عن عمليه الجمع والطباعه

كانت كدا

for (int row = 0; row < course.length; row++) {
        	for (int column = 0; column < course[column].length; column++) {
            	total[row] += course[row][column];
            	if (row == 0) {
                	System.out.print("student 5:  ");
            	} else {
                	System.out.print("student " + (row + 1) + ":  ");
            	}
            	System.out.println(total[row]);
        	}
    	}

وانا عدلتها لتكون كدا

for (int row = 0; row < course.length; row++) {
        	for (int column = 0; column < course[column].length; column++) {
            	total[row] += course[row][column];
        	}
        	System.out.print("student " + (row + 1) + ":  ");
        	System.out.println(total[row]);
    	}

يعنى يجمع ويطبع مره واحده

انما الاول كانت بتجمع وتطبع وبعدين تجمع وتطبع هكذا 4 مرات بس طبعا القيمه بتختلف فى كل مره

الكود بعد التعديل وشغال على الـ Test cases اللى انى وضعتيها

/**
 *
 * @author Mahmoud Kelany
 */
import java.util.Scanner;

public class GradesOfStudent {

	public static void finalGrades(double course[][], double total[]) {
    	total[total.length - 1] = 0.0;
    	System.out.println("the total grades for each student: ");

    	for (int row = 0; row < course.length; row++) {
        	for (int column = 0; column < course[column].length; column++) {
            	total[row] += course[row][column];
        	}
        	System.out.print("student " + (row + 1) + ":  ");
        	System.out.println(total[row]);
    	}
	}

	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
    	int rowCount = 5;
    	int colCount = 4;

    	double sum[] = new double[rowCount];
    	double studentGrade[][] = new double[rowCount][colCount];
    	System.out.println("Enter the gradesof the 5x4 array : ");

    	for (int row = 0; row < studentGrade.length; row++) {
        	for (int column = 0; column < studentGrade[0].length; column++) {
            	studentGrade[row][column] = input.nextDouble();
        	}
    	}
    	finalGrades(studentGrade, sum);
	}
}

وهذا هو الoutput

post-217802-033099900 1289148752_thumb.p

بالتوفيق :)

المرفقات
Arrayoutput.png

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 7 نوفمبر 2010 في 19:52

Software Developer
Mahmoudkelany.com


 

#7

شكراً

ماشاء الله عليك ربي يزيدك علم ويوفقك يارب لما يحب ويرضه

تم تعديل هذه المشاركة بواسطة *en* في 7 نوفمبر 2010 في 19:55

#8
*en* كتب:

شكراً

ماشاء الله عليك ربي يزيدك علم ويوفقك يارب لما يحب ويرضه

العفو :)

يارب جميعا يارب :)

الحمدلله الذى هدانا لهذا

دعواتك بالهدايه والتوفيق :)

Software Developer
Mahmoudkelany.com


 

#9

نصيحه كالعاده laugh.gif

حاولى تستخدمى الـ , for , while , if , loops , ... هتلاقى معظم اخطائك هنا

فلازم تراجعى على الموضوع دا

Software Developer
Mahmoudkelany.com


 

#10

علم..

أحياناً تكون اغلاطي تااااافه وماادري ووين صايره بالبرنامج بس إن شاء الله بحااول كثر ماأقدر أركز على هنقظه وادرب عليها اكثر عشان ماأغلط بالإمتحااااان!!

#11

سؤال جانبي :D

ما نوع المحرر الذي تستعمله في كتابة الاكواد ؟

لآنه يلزمني محرر ينسخ التنسيقات و الألوان للكود على WORD :P

و شكراً جزيلاً

#12

جرب eclipse فهو رائع

لا أعرف إن كان NetBeans يدعم rtf أو لا

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#13
aohammed كتب:

سؤال جانبي :D

ما نوع المحرر الذي تستعمله في كتابة الاكواد ؟

لآنه يلزمني محرر ينسخ التنسيقات و الألوان للكود على WORD :P

و شكراً جزيلاً

مش فاهم قصدك بس ان كان على المحرر فانا شغال netbeans

بس مش فاهم تقصد ايه بالتنسيقات

Software Developer
Mahmoudkelany.com


 

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…