作业帮 > 综合 > 作业

在java中怎么比较三个整数大小例如(a ,b,c);并从小到大输出

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 23:03:20
在java中怎么比较三个整数大小例如(a ,b,c);并从小到大输出
import java.util.*;
public class Exercise06
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); //利用键盘输入功能
System.out.print("a=");
int a = input.nextInt() ; //输入数字a 只能为int类型
System.out.print("b=");
int b = input.nextInt() ;
System.out.print("c=");
int c = input.nextInt() ;
Exercise06 e = new Exercise06() ;
e.sort(a,b,c);
}
void sort(int a,int b,int c)
{
int temp = 0 ;
if(a>b){
temp = a;
a = b ;
b = temp ;
}
if(a>c){
temp = a;
a = c ;
c = temp ;
}
if(b>c){
temp = b;
b = c ;
c = temp ;
}
System.out.println(a+","+b+","+c);
}
}
不过我还是建议你多用一楼的方法