Question

What are the errors in this ? public class Mystery { public static void main(String[] args)...

What are the errors in this ?

public class Mystery {
public static void main(String[] args) {

double initialSavings = 10000;
double interestRate = 0.05;
double currSavings = 0;
int i;
  
System.out.println("\nAnnual savings 5 years: ");
currSavings = initialSavings;
for (i = 0, i < 5, ++i);
currSavings = (currSavings * interestRate);
System.out.println("$" + currSavings);
}
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER: Here I corrected the code and now it is giving the proper output explanation is given as comment in the code.

CODE:

public class Mystery {
public static void main(String[] args) {

       double initialSavings = 10000;
       double interestRate = 0.05;
       double currSavings = 0;
       int i;
  
   System.out.println("\nAnnual savings 5 years: ");
   currSavings = initialSavings;
   for ( i = 0; i < 5; ++i)// here , is there instead of ;(semicolon).
   currSavings = (currSavings * interestRate);
   System.out.println("$" + currSavings);
}
  
}

OUTPUT:

Annual savings 5 years: $0.003125

Add a comment
Know the answer?
Add Answer to:
What are the errors in this ? public class Mystery { public static void main(String[] args)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT