ICSE Class 10 Computer Applications Question 57 of 76

Revising Basic Java Concepts — Question 61

Back to all questions
61
Question

Question 38

Find the error :

x = 3;	
y = 4;	
z = math.power(x*x, y/2);	
Answer

The errors are as follows:

  1. The variables — x, y, z, are not declared. They need to be declared before they can be used.
  2. The letter 'm' in math should be in uppercase as Java is a case-sensitive language. Also, the correct name of the function is pow. Hence, it must be written as Math.pow().

The correct code snippet is as follows:

int x = 3;	
int y = 4;	
double z = Math.pow(x*x, y/2);