The value of y is calculated as follows:-
y = 4x3 + 2x 6 when x > 5
y = 3x2 4y + 12 when x < 5
y = 6x 5 when x = 5
Write a program that accepts the value x and then computes the value of y.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input x:");
int x = scanner.nextInt();
double y;
if (x > 5) {
y = 4 * Math.pow(x, 3) + 2 * Math.pow(x, 6);
} else if (x < 5) {
y = 3 * Math.pow(x, 2) + 12;
} else {
y = 6 * Math.pow(x, 5);
}
System.out.println("y = " + y);
}
Comments
Leave a comment