Q8
Consider the program given below.
import java.lang. Math. *;
public class Main{
public static void main(String args[])
System.out.println(PI*1/PI);
}
}
What will be the output if the above programis executed:
a. It will give compile-time error
b. It will give run-time error
c. 1.0
d. 3.14
Answers
Answer:
so the correct option is a (compilation time error).
Explanation:
it will give compile time error
the main error is you have not initialized variable PI
so the error in compiling will come as 'cannot find variable PI.
the second error is you have not put curly bracket( { ) after public static void main(String[]args)....
so the correct program is:
import java.lang. Math. *;
public class Main2{
public static void main(String args[])
{
double PI = 3.14;
System.out.println(PI*1/PI);
}
}
and when you run this program you get the output as 1.0
i have written,compiled and run in bluej....
and bluej is a windows app...it doesn't work on web...
you can also try javatpoint , tutorialspoint etc(for web)
to reach javatpoint and tutorialspoint just search 'online java compiler' on google.
Thanks!!
hope it helps!!
plz mark me as brainliest if it helps!!
Answer:-
The program results in compile time error because of two reasons.
- PI is not declared and initialised.
- bracket is not given after starting of main() method.