要求
输入三个整数x,y,z,请把这三个数由小到大输出。
实施
package com.sy.pm;
import java.util.Scanner;
public class Test9 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double x = 0;
double y = 0;
double z = 0;
x = in.nextLong();
y = in.nextLong();
z = in.nextLong();
String msg = "";
//方法1
if (x < y && x < z){
if(y > z){
msg = x+"<"+z+"<"+y;
}else {
msg = x+"<"+y+"<"+z;
}
}else if(y < x && y < z) {
if (x > z) {
msg = y + "<" + z + "<" + x;
} else {
msg = y + "<" + x + "<" + z;
}
}else {
if(x < y){
msg = z+"<"+x+"<"+y;
}else{
msg = z+"<"+y+"<"+x;
}
}
System.out.println(msg);
//方法2
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
if (a > b){
int temp = a;
a = b;
b = temp;
}
if (a > c){
int temp = a;
a = c;
c = temp;
}
if (b > c){
int temp = b;
c = b;
b = temp;
}
System.out.println(a+" "+b+" "+c);
}
}
版权属于:牧瀬くりす
本文链接:https://hcyacg.com/tutorial/Java-1.html
本站文章采用知识共享署名4.0 国际许可协议进行许可,允许非商业转载,但必须注明出处!