package variousprograms;
import java.util.*;
public class InputStats
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int a;
int b;
int c;
int d;
int e;
System.out.println("First Integer ");
a = input.nextInt();
System.out.println("Second Integer ");
b = input.nextInt();
System.out.println("Third Integer ");
c = input.nextInt();
System.out.println("Fourth Integer ");
d = input.nextInt();
System.out.println("Fifth Integer ");
e = input.nextInt();
System.out.println("Maximum is " + Math.max(Math.max(Math.max(Math.max(a,b), c), d), e));
System.out.println("Minimum is " + Math.min(Math.min(Math.min(Math.min(a,b), c), d), e));
System.out.println("Mean is " + (a + b + c + d + e)/5.0);
}
}
このコードでは、各整数に5つの変数を使用して5つの整数のセットの最小値、最大値、平均値を求めました。問題は、5つではなく4つの変数を使用するはずであり、ifやloopなどの制御文を使用できないことです。整数の最小値
私は既に書いたコードをどのように変更すればよいですか?
これは宿題の問題のように見えます。あなたのインストラクターは三項演算子を制御文と見なしますか? – vallismortis
私は三項演算子を使用できません – TheLegend
これはばかげた問題です。 [Math.max](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Math.java#Math.max%28int%2Cint %29)メソッドは3項演算子を使用します: 'public static long max(long a、long b){return(a> = b)? a:b; } '。 – vallismortis