Ask Question

Assume there is a variable, h already assigned a positive integer value. Write the code necessary to assign its square to the variable g. For example, if h had the value 8 then g would get the value 64.

+3
Answers (1)
  1. 10 October, 17:30
    0
    public class num10 {

    public static void main (String[] args) {

    int h = 8;

    double g = Math. pow (h, 2);

    System. out. println ("The Squared value of "+h+" is "+g);

    }

    }

    Explanation:

    Using Java programming Language, As stated in the question, h is declared as an int and assigned the value of 8.

    a variable g is declared and assigned the square of h using java's power method in Math class

    The squared value is then outputed to the console.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume there is a variable, h already assigned a positive integer value. Write the code necessary to assign its square to the variable g. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers