輸入兩個(gè)整數(shù) x 和 y,請你編寫一個(gè)函數(shù),
int max(int x, int y)
,計(jì)算并輸出 x 和 y的最大值。
輸入格式
共一行,包含兩個(gè)整數(shù) x
和 y。
輸出格式
共一行,包含一個(gè)整數(shù),表示兩個(gè)數(shù)中較大的那個(gè)數(shù)。
數(shù)據(jù)范圍
?100≤x,y≤100文章來源:http://www.zghlxwxcb.cn/news/detail-691796.html
輸入樣例:
3 6
輸出樣例:
6
import java.util.Scanner;
public class Main {
public static void main(String []args)
{
Scanner cin=new Scanner(System.in);
int x=cin.nextInt();
int y= cin.nextInt();
System.out.println(max(x,y));
}
public static int max(int x, int y)
{
if(x>y)
{
return x;
}
else if(x<y)
{
return y;
}
else return x;
}
}
?文章來源地址http://www.zghlxwxcb.cn/news/detail-691796.html
到了這里,關(guān)于JAVA-x和y的最大值的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!