Back
import java.util.*;
public class example3 {
public static void main(String[] args)
{
//Variable declarations for input and calculations
int a, b, c, min, max;
double average;
//Input
System.out.println("Example 3: ");
System.out.println("Enter a value for 'a': ");
/*readInt is another method, that will return an int
and it will not take in any parameters*/
a = readInt();
System.out.println("Enter a value for 'b': ");
b = readInt();
System.out.println("Enter a value for 'c': ");
c = readInt();
//Processing and Calculations
//A is greater than B
if (a > b)
{
//A is greater than B AND A is greater than C
if (a > c)
{
max = a;
}
//A is greater than B BUT A is not greater than C
else
{
max = c;
}
}
//A is not greater than B AND B is greater than C
else if (b > c)
{
max = b;
}
//A is not greater than B AND B is not greater than C
else
{
max = c;
}
min = Math.min(Math.min(a, b), c);
average = (a + b + c) / 3;
//Output
System.out.println("Min = " + min);
System.out.println("Max = " + max);
System.out.println("Average = " + average);
}
public static int readInt()
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
return x;
}
}
Top |