Computer Applications
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);
}
}
Java
Java Math Lib Methods
6 Likes
Answer
z = 5.0
Working
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
Answered By
3 Likes
Related Questions
Predict the output :
class FindFac { public static void main (String args[]) { for(int i = 2; i <= 100; i++) { System.out.print("Factors of" + i + ": "); for(int j = 2; j < i; j++) if((i % j) == 0) System.out.print(j + " "); System.out.println(); } } }
State the number of bytes occupied by char and int data types.
Write one difference between / and % operator.
Predict the output :
class Power { public static void main(String args[]) { int e = 5, result, i; result = 1 ; i = e ; while(e > 0) { result *= 2 ; e--; } int n = result /2, p = i - 1; System.out.println("2 to the power of " + i + " is " + result); System.out.println("2 to the power of " + p + " is " + n); } }