تسجيل الدخول

مشاهدة النسخة كاملة : طلب توضيح كود



cccccc55
10-03-2007, 01:43 PM
// array7.java
import javax.swing.*;
class array7{
public static void main(String args[]){
int num[] = new int[] {4, 6, 2, 3, 9, 5, 8, 1, 10, 7};
int temp;
String title="The results of the Example (1-7)";
String output="Array contents in original order:\n";
for(int i=0; i<num.length; i++)
output+=num[i]+" ";
for(int i=1; i<num.length; i++)
for(int j=0; j<num.length-1; j++)
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
output+="\n\nArray contents in ascending order:\n";
for(int i=0; i<num.length; i++)
output+=num[i]+" ";
JOptionPane.showMessageDialog(null, output, title,
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}

ارجو توضيح المقطع
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;

cccccc55
10-03-2007, 04:42 PM
// array7.java
import javax.swing.*;
class array7{
public static void main(String args[]){
int num[] = new int[] {4, 6, 2, 3, 9, 5, 8, 1, 10, 7};
int temp;
String title="The results of the Example (1-7)";
String output="Array contents in original order:\n";
for(int i=0; i<num.length; i++)
output+=num[i]+" ";
for(int i=1; i<num.length; i++)
for(int j=0; j<num.length-1; j++)
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
output+="\n\nArray contents in ascending order:\n";
for(int i=0; i<num.length; i++)
output+=num[i]+" ";
JOptionPane.showMessageDialog(null, output, title,
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}

cccccc55
10-03-2007, 05:03 PM
http://www.montada.com/http://www.ksa-7be.com/up/up19/f08b585f42.jpg (http://www.ksa-7be.com/up)

cccccc55
10-03-2007, 05:04 PM
لو تكرمتم اريد توضيح لهذا الجزء
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;