我对此很新,而且我一直在做我的任务,所以任何人都可以请帮忙。我在排序输出时遇到问题。这里是代码。如何对数据进行排序
import java.util.Scanner;
public class CJPSA5 {
public static void main(String args[]){
Scanner in= new Scanner(System.in);
int num;
int m;
int r;
System.out.print("Please Enter your Number: ");
num = in.nextInt();
if (num <= 0) {
System.out.println("Not Accepted!");
} else {
System.out.println("The Factor of "+ num + " " + "are:");
for (m = 1; m <= num; m++) {
if (num % m == 0) {
System.out.print(m + "\t");
System.out.print(j + "\t");
}
}
}
}
}
}
System.out.println();
System.out.println("Thank You!");
}
}
预期的输出是这样的。
Please Enter your Number: 24
The Factor of 24 are:
1 -1 2 -2 3 -3 4 -4 6 -6 8 -8 12 -12 24 -24
现在我想成为输出类似
1 2 3 4 6 8 12 24 -1 -2 -3 -4 -6 -8 -12 -24
进行排序我真的希望有人能帮助我,对不起,我错了语法。
你的问题的代码是不是你正在使用的代码。为什么不? – immibis
您的代码将不会编译 – tapananand
您正在打印出一个j变量,但是在您的代码中没有。尝试保存ArrayList的答案,然后对它们进行排序,而不是打印。 –