【java入門】使用選擇法確定輸入最大值
阿新 • • 發佈:2018-12-06
package com.demo;
import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("輸入3科成績:java,android,sql");
int java = scanner.nextInt();
int android = scanner.nextInt();
int sql = scanner.nextInt();
int maxScore = java;
if(maxScore < android){
maxScore = android;
}
if (maxScore < sql){
maxScore = sql;
}
System.out.println("最大成績為:"+maxScore);
思路在於定義一個變數maxScore,經過比較,總是將最大值儲存在該變數中,最後輸出該變數即可
“`