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

جمع المصفوفات ....... أرجو المساعدة

بدأه السماك في 21 مايو 2009 · 4 رد · 520 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
Develop a program to do the folloing operations :
1. Initialize 2 one dimensional arrays ( called A & B ) (10 elements)with random number .
The number entered by you.
2. find the sum of the tow arrays in a new array ( called sun )
3. find the positive of the max element of the new array.
4. Print the thee araays (A , b and sun).

Example :

Array A : 1 4 3 2 6 7 4 3 1 1
Array B : 1 2 3 4 5 6 7 8 9 1

Result Array Sum : 2 6 6 6 11 13 11 11 10 2 

Max found at ( 4 )






My tryng with this program :

import javax.swing.*;
public class  Array7{
  public static void main(String[] args){
  int A[]= {1, 4,3,2,6,7,4,3,1,1};
  int B[]=  {1,2,3,4,5,6,7,8,9,1};
  int sum [] = new int [10];
	for (int i = 0;i < 9;i++ ){

	}

   System.out.println("A Array >>");

	for (int i = 0; i < 9;i++ ){
	System.out.println("  " + A);
	}



	System.out.println("B Array >> ");




	for (int i = 0;i < B.length;i++ ){
	System.out.println("  " + B);
	}


	   for ( int i = 0; i < 9; i++){
		sum = (A + B);
}

	 System.out.println("  "+sum );

  }
}

تم تعديل هذه المشاركة بواسطة السماك في 21 مايو 2009 في 22:47

#2

ما هو المشكل؟؟

#3

أهلا وسهلا بك أستاذي الفاضل herch

المشكلة في السؤال أنه طالب مني جمع مصفوفتين بمصفوفة اسمها sum ولم أستطع أن اجمعها كل ما أريد أن انفذ برنامجي يقول هنالك خطأ

وطلباته كثيرة طالب ال max ومشكلتي بالضبط في الفقرات التالية من السؤال :

2. find the sum of the tow arrays in a new array ( called sun )

3. find the positive of the max element of the new array.

4. Print the thee araays (A , b and sun).

أرجو مساعدتي يا استاذي الفاضل

#4

يا أخي أنا لست أستاذا، أنا مازلت أدرس مثلي مثلك

هذا الكود الذي كتبته لكن معدل، قارنه بالكود الذي كتبته من قبل حتى تستفيد


public class Array7{
public static void main(String[] args){

int max = 0;
int A[] = {1,4,3,2,6,7,4,3,1,1};
int B[] = {1,2,3,4,5,6,7,8,9,1};
int sum [] = new int [10];

//we add the elements of the two array, and put the result in sum array
for (int i = 0;i < sum.length;i++ ){
sum = A + B;
}
//we compare each element in sum array with the max variable, and if it is
//greater, we put its value in the max variable
for ( int i = 0; i < sum.length; i++){
if (sum > max) {
max = sum;
}
}
System.out.println("A Array >>");

for (int i = 0; i < A.length;i++ ){
System.out.print(A + " ");
}

System.out.println();
System.out.println("B Array >> ");

for (int i = 0; i < B.length;i++ ){
System.out.print(B + " ");
}

System.out.println();
System.out.println("Sum Array >>");

for ( int i = 0; i < sum.length; i++){
System.out.print(sum + " ");
}
System.out.println();
System.out.println("The max of the sum arrays is: " + max);
}
}

#5

ألف شكر أخوي الفاضل

والله أنك استاذ وبطل

على فكرة أنا أول مرة أدرس الجافا

يعني لا تستغرب عسر الفهم اللي عندي

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