为什么这段代码不起作用? [英] Why this code didn't work ?
本文介绍了为什么这段代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello all
我正在使用Jcreator v3和Eclips来运行我的代码,但是最后一个应用程序没有看到我的代码,运行我的代码之后我只看到黑色表单,请告诉我为什么这段代码不起作用?
此代码对数组进行排序。
这是我的代码:
Hello all
I am using "Jcreator v3" and "Eclips" to run my code but the last application didn't see my code , after run my code I see just the black form,please tell me why this code didn't work ?
This code to sort an array .
This is my code :
import javax.swing.JOptionPane;
public class anything {
public static void main(String[] args)
{
// inserting array
int [] RandomArray = {1,2,5,3,4,6,7,8};
//sorting array "Here the program didn't read"
int [] Sortedarray = new int [8];
for (int i = 0; i < RandomArray.length; i++)
{
int count = 0 ;
int x=0;
for (int j = 0; j < RandomArray.length; j++)
{
if (RandomArray[i]!=0)
{
if (RandomArray[i]<RandomArray[j])
{
Sortedarray[count] = RandomArray[i];
x=i;
}else
{
Sortedarray[count] = RandomArray[j];
i=j;
x=j;
}
}
}
RandomArray[x]=0;
count=count+1;
i=0;
}
//write sorted array
Sortedarray[0]=1;
for (int z = 0; z < Sortedarray.length; z++)
{
System.out.println("This is sorted array:"+Sortedarray[z]);
}
}
}
推荐答案
检查下面的评论
Check the comment below
import javax.swing.JOptionPane;
public class anything {
public static void main(String[] args)
{
// inserting array
int [] RandomArray = {1,2,5,3,4,6,7,8};
//sorting array "Here the program didn't read"
int [] Sortedarray = new int [8];
for (int i = 0; i < RandomArray.length; i++)
{
int count = 0 ;
int x=0;
for (int j = 0; j < RandomArray.length; j++)
{
if (RandomArray[i]!=0)
{
if (RandomArray[i]<RandomArray[j])
{
Sortedarray[count] = RandomArray[i];
x=i;
}else
{
Sortedarray[count] = RandomArray[j];
i=j;
x=j;
}
}
}
RandomArray[x]=0;
count=count+1;
i=0; //********Problem is here i is being reinitialized to 0 so the loop never ends
}
//write sorted array
Sortedarray[0]=1;
for (int z = 0; z < Sortedarray.length; z++)
{
System.out.println("This is sorted array:"+Sortedarray[z]);
}
}
}
这篇关于为什么这段代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文