ICSE Class 10 Computer Applications Question 52 of 76

Revising Basic Java Concepts — Question 56

Back to all questions
56
Question

Question 33

Predict the output :

class Test {
    public static void main (String args[]) { 
        double x, y, z ;
        x = 3;
        y = 4;
        z = Math.sqrt(x * x + y * y); 
        System.out.println("z = " + z);
    }
}
Answer
Output

z = 5.0

Explanation

z = Math.sqrt(x * x + y * y)
  ⇒ Math.sqrt(3.0 * 3.0 + 4.0 * 4.0)
  ⇒ Math.sqrt(9.0 + 16.0)
  ⇒ Math.sqrt(25.0)
  ⇒ 5.0