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

عندي مصفوفة من بعدين أريد أن انشئ أخرى منها مع جعل الصفوف أعمدة والعكس من غيرعكس القيم

بدأه Islamic_boy600 في 19 مايو 2008 · 2 رد · 567 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

وجدت هذا الكود لكنه يعكس القيم مع التحويل فيجعل آخر قيمة لعمود الاولى هو اول قيمة لصف الثانية لكني أريد فقط أن اجعل الصفوف اعمدة والعكس من غير تغيير اماكن القيم هذا هو الكود

public static void main(String[] args) {
		int[][] forward = {
			{ 1, 2, 3, 4 },
			{ 5, 6, 7, 8 }
		};
		int rows = forward.length;
		int cols = forward[0].length;
		int[][] reverse = new int[rows][cols];
		for(int i = rows-1; i >= 0; i--) {
			for(int j = cols-1; j >= 0; j--) {
				reverse[rows-1-i][cols-1-j] = forward[j];
			}
		}
		for(int i = 0; i < rows; i++) {
			for(int j = 0; j < cols; j++) {
				System.out.print(reverse[j]);
				if(j < cols-1)
					System.out.print(", ");
			}
			System.out.println();
		}
	}
}
#2

هذا التعديل المطلوب

أخي الكريم

أرجو أن يكون فيه الفائدة

 

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright © 2008</p>
 *
 * <p>Company: </p>
 *
 * @author Essam-ag
 * @version 1.0
 */
public class Reverse {
    public Reverse() {
    }

    public static void main(String[] args) {
        int[][] forward = { 
                          {1, 2, 3, 4}, 
                          {5, 6, 7, 8}
        };
        int rows = forward.length;
        int cols = forward[0].length;
        int[][] reverse = new int[cols][rows];
        for (int i = 0; i < cols; i++) {
            for (int j = 0; j < rows; j++) {
                reverse[j] = forward[j];
            }
        }
        for (int i = 0; i < cols; i++) {
            for (int j = 0; j < rows; j++) {
                System.out.print(reverse[j]);
                if (j < rows - 1)
                    System.out.print(", ");
            }
            System.out.println();
        }
    }
}

ready to do full students projects

digitalscenter@hotmail.com

+966530357742

#3

جزاك الله خيراأسأل الله ان يجعله في ميزان حسناتك وهذا هو الكود كامل إذا أرادنا أن نجعل المستخدم يدخل القيم

import java.util.*;
public class Main {
static Scanner console = new Scanner(System.in);
	public static void main(String[] args) 
	{
	 System.out.print("Please Enter 8 number");   
   int[][] arr = new int [2][4];
 for(int i = 0; i < 2; i++) {
for(int j = 0; j < 4; j++) {
 arr[j]=console.nextInt();
}
}  
   trans(arr);
}
public static void trans (int[][] arr)
{
int rows = arr.length;
int cols = arr[0].length;
int[][] reverse = new int[cols][rows];
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
reverse[j] = arr[j];
}
}
for(int i = 0; i < cols; i++) {
for(int j = 0; j < rows; j++) {
System.out.print(reverse[j]);
if(j < cols-1)
System.out.print(" , ");
}
System.out.println();
}
}
}

تم تعديل هذه المشاركة بواسطة Islamic_boy600 في 19 مايو 2008 في 11:26

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

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

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

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

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