Answer to Question #318948 in Java | JSP | JSF for makky

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".
1
Expert's answer
2022-03-27T05:46:54-0400
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");
        }

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS