Inactive Tutor answered 07/10/21
Works just fine for me.....
Output is:
The interest earned is $1190.0
The value of the investment after one year is $18190.0
are you sure you are issuing the proper commands to compiler and run your code?
Mathias E.
asked 07/10/21public class Interest {
public static void main(String[] args) {
/* Declare the variables. */
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // Interest earned in one year.
/* Do the computations. */
principal = 17000;
rate = 0.07;
interest = principal * rate; // Compute the interest.
principal = principal + interest;
// Compute value of investment after one year, with interest.
// (Note: The new value replaces the old value of principal.)
/* Output the results. */
System.out.print("The interest earned is $");
System.out.println(interest);
System.out.print("The value of the investment after one year is $");
System.out.println(principal);
} // end of main()
} // end of class Interest
Why it was producing error when I run the code in my interpreter?
Error : class interest is public, should be declared in a file named Interest.java
Inactive Tutor answered 07/10/21
Works just fine for me.....
Output is:
The interest earned is $1190.0
The value of the investment after one year is $18190.0
are you sure you are issuing the proper commands to compiler and run your code?
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.