用java编写一个程序,比较任意三个数,按从小到大的顺序输出,一定要用构造方法。
1个回答
2018-04-08 · 知道合伙人互联网行家
关注
展开全部
import java.util.Arrays;
import java.util.Scanner;
public class DataCompare {
public static void main(String[] args) {
int[] ary = new int[3];
Scanner scanner = new Scanner(System.in);
for(int i = 0; i < ary.length; i++){
System.out.print("Please input a digit(Seq: " + (i+1) + "): ");
ary[i] = scanner.nextInt();
}
Arrays.sort(ary);
System.out.print("After sorted by ASC, the numbers are: ");
for(int i = 0; i < ary.length; i++){
System.out.println(ary[i] + "\t");
}
}
}
--------------------------testing
Please input a digit(Seq: 1): 13
Please input a digit(Seq: 2): 25
Please input a digit(Seq: 3): 9
After sorted by ASC, the numbers are: 9
13
25
import java.util.Scanner;
public class DataCompare {
public static void main(String[] args) {
int[] ary = new int[3];
Scanner scanner = new Scanner(System.in);
for(int i = 0; i < ary.length; i++){
System.out.print("Please input a digit(Seq: " + (i+1) + "): ");
ary[i] = scanner.nextInt();
}
Arrays.sort(ary);
System.out.print("After sorted by ASC, the numbers are: ");
for(int i = 0; i < ary.length; i++){
System.out.println(ary[i] + "\t");
}
}
}
--------------------------testing
Please input a digit(Seq: 1): 13
Please input a digit(Seq: 2): 25
Please input a digit(Seq: 3): 9
After sorted by ASC, the numbers are: 9
13
25
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询