Question #318948

The square of an integer refers to the result of multiplying the integer with itself once. While the cube of an integer refers to the result of multiplying the integer with itself twice. As long as you know that, you could easily solve this!


Instructions:

  1. Input three integers and compute the cubes of each of them.
  2. Check if the sum of the cubes are positive. If it is, print out "Positive", and if not, print out "Negative".

Expert's answer

import java.util.Scanner;
import static java.lang.Math.pow;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter x: ");
        int x = (int) pow(in.nextInt(),3);

        System.out.print("Enter y: ");
        int y = (int) pow(in.nextInt(),3);

        System.out.print("Enter z: ");
        int z = (int) pow(in.nextInt(),3);

        int sum = x + y + z;

        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
        if (sum >= 0) {
            System.out.print("Positive");
        } else {
            System.out.print("Negative");
        }

    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS