輸入任意正整數a,b,c,返回最大值
1.本文用到了java.util.Scanner包,利用Scanner in = new Scanner(System.in);實現界面輸入數據
2.源代碼如下:
package chapter1;
import java.util.Scanner;
public class one {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int a = 0, b = 0, c = 0;
System.out.print("請輸入第一個數值:");
a = in.nextInt();
System.out.print("請輸入第二個數值:");
b = in.nextInt();
System.out.print("請輸入第三個數值:");
c = in.nextInt();
int max = a;
if (b > max)
max = b;
else if (c > max)
max = c;
System.out.print("最大值爲:"+max);
}
}
3.運行結果: