记得把分给我!
import java.util.Scanner;
/**
* 由控制台输入三个数,并升序排序
*
* @author young
*
*/
public class Example {
public static void main(String[] args) {
int num1, num2, num3;
Scanner sc = new Scanner(System.in);
System.out.println("输入第一个数:");
num1 = sc.nextInt();
System.out.println("输入第二个数:");
num2 = sc.nextInt();
System.out.println("输入第三个数:");
num3 = sc.nextInt();
/* 进行排序 */
if (num1 >= num2) {
if (num2 >= num3) {
System.out.print(num3 + "<=" + num2 + "<=" + num1);
} else {
if (num1 >= num3) {
System.out.print(num2 + "<=" + num3 + "<=" + num1);
} else {
System.out.print(num2 + "<=" + num1 + "<=" + num3);
}
}
} else {
if (num1 >= num3) {
System.out.print(num3 + "<=" + num1 + "<=" + num2);
} else {
if (num2 >= num3) {
System.out.print(num1 + "<=" + num3 + "<=" + num2);
} else {
System.out.print(num1 + "<=" + num2 + "<=" + num3);
}
}
}
}
}
Arrays.sort(score);
System.out.println("\n" + "由小到大排列为:");
for(int i = 0;i < score.length;i++)
{
System.out.print(score[i]+" ");
}
不是完整代码哈 在main函数下运行
Scanner sca = new Scanner(System.in);
int num1 = sca.nextInt();
int num2 = sca.nextInt();
int num3 = sca.nextInt();
if(num3>=num2 && num2>=num1){
System.out.print(num1+"<="+num2+"<="+num3);
}else if(num2>=num3 && num3>=num1){
System.out.print(num1+"<="+num3+"<="+num2);
}else if(num>=num3 && num1>=num3){
System.out.print(num3+"<="+num1+"<="+num2);
}else if(){
......还有几种情况自己写写吧
感觉循环可以做 暂时没想出来
排序比较流行的就是冒泡法了,代码如下:
int[] num = { num1, num2, num3 };
//冒泡法排序,对num数组中的整数进行排序,从小到大
for (int i = 0; i < num.length; i++) {
for (int j = i; j < num.length; j++) {
int num0;
if (num[i] > num[j]) {
num0 = num[i];
num[i] = num[j];
num[j] = num0;
}
}
}
num1 = num[0];
num2 = num[1];
num3 = num[2];
直接排序然后分别赋值就可以了