スキャナーを使用して 3 つの整数 (正の数) を読み取るプログラムを作成し、3 のうち最大の数を表示します。&&
(演算子またはのいずれも使用せずに完了してください||
。これらの演算子については、すぐにクラスで説明します。同様に、ループは必要ありません。)
Some sample run:
Please input 3 integers: 5 8 3
The max of three is: 8
Please input 3 integers: 5 3 1
The max of three is 5
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: ");
String x = keyboard.nextLine();
String y = keyboard.nextLine();
String z = keyboard.nextLine();
int max = Math.max(x,y,z);
System.out.println(x + " " + y + " "+z);
System.out.println("The max of three is: " + max);
}
}
このコードの問題点と、3 つの異なる値を入力したときに最大値を見つける方法を知りたいです。