Люди добрые подскажите как можно сократить код (там где if начинается) или скажите если команда какая меняет тип переменной с double на int
import java.util.Scanner;
public class F1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Введите три числа.");
double sc1 = sc.nextDouble();
double sc2 = sc.nextDouble();
double sc3 = sc.nextDouble();
System.out.print("Среднее арифметическое\t");
if (sc1 % 1 == 0) System.out.print((int)sc1);
else System.out.print(sc1);
System.out.print("\t");
if (sc2 % 1 == 0) System.out.print((int)sc2);
else System.out.print(sc2);
System.out.print("\t");
if (sc3 % 1 == 0) System.out.println((int)sc3);
else System.out.println(sc3);
double a = (sc1 + sc2 + sc3) / 3;
if (a % 1 == 0) System.out.println("Будет: " + (int)a);
else System.out.println("Будет: " + a);
}
}
Ответ
Введите три числа.
1,3
2
3
Среднее арифметическое 1.3 2 3
Будет: 2.1
Process finished with exit code 0