用java语言程序,比较三个数的大小,输出最大的那个数
3个回答
展开全部
你好,帮你写了一个例子:
import java.lang.Math;
import java.util.Scanner;
public class max {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please input 3 integers: ");
int x = Integer.parseInt(keyboard.nextLine());
int y = Integer.parseInt(keyboard.nextLine());
int z = Integer.parseInt(keyboard.nextLine());
int max = Math.max(x,y);
if(max>y){ //suppose x is max then compare x with z to find max number
max = Math.max(x,z);
}
else{ //if y is max then compare y with z to find max number
max = Math.max(y,z);
}
System.out.println("The max of three is: " + max);
}
}
请记得采纳哦!
import java.lang.Math;
import java.util.Scanner;
public class max {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please input 3 integers: ");
int x = Integer.parseInt(keyboard.nextLine());
int y = Integer.parseInt(keyboard.nextLine());
int z = Integer.parseInt(keyboard.nextLine());
int max = Math.max(x,y);
if(max>y){ //suppose x is max then compare x with z to find max number
max = Math.max(x,z);
}
else{ //if y is max then compare y with z to find max number
max = Math.max(y,z);
}
System.out.println("The max of three is: " + max);
}
}
请记得采纳哦!
展开全部
源代码如下:
public class Test
{
public static void main(String arg[])
{int
a; int b; int c; int temp;
if (a<b)
{temp=b;
b=a;
a=temp;
}
if (b<c)
{temp=b;
b=c;
c=temp;
}
if (a<b)
{temp=b;
b=a;
a=temp;
}
System.out.println("最大的数是:"a"+=);
}
}
public class Test
{
public static void main(String arg[])
{int
a; int b; int c; int temp;
if (a<b)
{temp=b;
b=a;
a=temp;
}
if (b<c)
{temp=b;
b=c;
c=temp;
}
if (a<b)
{temp=b;
b=a;
a=temp;
}
System.out.println("最大的数是:"a"+=);
}
}
更多追问追答
追问
亲,这个比较大小是不是也可以用if,else,,
追答
if...else和if 效果一样的,可以的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
!!
追问
怎么了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询