Computer Applications
Answer
The errors are as follows:
- The variables — x, y, z, are not declared. They need to be declared before they can be used.
- The letter 'm' in
math
should be in uppercase as Java is a case-sensitive language. Also, the correct name of the function ispow
. Hence, it must be written asMath.pow()
.
The correct code snippet is as follows:
int x = 3;
int y = 4;
double z = Math.pow(x*x, y/2);
Related Questions
Give the output of the following program segment and also mention how many times the loop is executed.
int i; for (i = 5 ; i > 10; i++) System.out.println(i); System.out.println(i * 4);
Find the error
for(count = 0, count < 5, count = count + 1) System.out.println("This is count:" + count); System.out.println("Done!");
Find the error:
class Test { public static void main (String args[]) { int x = 10; if(x == 10) { int y = 20; System.out.println("x and y: "+ x +" "+ y); x = y * 2; } y = 100; System.out.println("x is"+ x); } }
Write a program that inputs a number and tests if the given number is a multiple of both 3 and 5.