本题要求将输入的任意3个整数从小到大输出。
输入格式: 输入在一行中给出3个整数,其间以空格分隔。
输出格式: 在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例: 4 2 8 输出样例: 2->4->8
比较结果和样例相同,但是PTA提交不上去,说答案错误。 有没有人帮忙看看那里的问题
代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
int d=Math.max(a, Math.max(b, c));
int e=Math.min(a, Math.min(b, c));
int f=0;
if(a!=d&&a!=e)
{
f=a;
}else if(b!=d&&b!=e)
{
f=b;
}else if(c!=d&&c!=e)
{
f=c ;}
System.out.println(Math.min(a, Math.min(b, c))+"->"+f+"->"+Math.max(a, Math.max(b, c)));
}
}