not a problem. The rule is initialize locals before using. We use our locals only if they get initialized (area formula is inside the if-statement). If the If-block not runs, area takes its default value 0.0
Answer is A.
public class Triangle {
static double area;
int b=2, h=3;
public static void main(String[] args) {
double p,b,h;
if (area==0) {
b=3;
h=4;
p=0.5;
area=p*b*h;
}
System.out.println(area);
}
}
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Sreeni_A
5 months, 2 weeks agoRdharma
7 months, 1 week agonamaoo
4 months, 2 weeks agoRdharma
7 months, 1 week agoCreazyyyyGirl
10 months, 3 weeks agoRajeevkuamr
1 year agoKolodets
9 months, 1 week agoKolodets
9 months, 1 week agocarloswork
1 year, 3 months agoUAK94
1 year, 3 months ago