Define a problem with user input, user output and mathematical
computation.
Include source code and output. If no output explain the reason why
and what you are going to do make sure it does not happen again aka
learning from your mistakes. (JAVA)
Problem:
Pseudocode:
Code:
Output:
Problem: To find the simple interest using the principal amount given and rate of interest at which it is given and the time period for which it is given.
Psuedo Code:
Taking input from the user for the values, p, r, t
if all values > 0
calculate interest
print the interest
else
return with an error
Following is the JAVA Code for the same.
import java.util.Scanner;
public class SimpleInterest {
public static void main(String args[]) {
Scanner scan = new
Scanner(System.in);
System.out.println("-------This is
the simple Interest calculator---------");
System.out.println("Enter the
principal Amount, Rate of interest, Time period in years");
int p = scan.nextInt();
double r = scan.nextDouble();
double t = scan.nextDouble();
if(p>0 && r>0
&& t>0) {
double interest
= (p*r*t)/100;
System.out.println("Interest: " + interest);
System.out.println("Accumulated Amount: " + (interest + p));
}else {
System.out.println("All Values should be positive");
}
}
}
Following is the snippet of the output.
So as to make sure that the user does not repeat the mistake of putting the wrong values as the input the code is printing the error if the wrong values are given. That the values should be positive.
Following is the snippet for the same.
That was a nice
question to answer
Friend, If you have any doubts in understanding do let me know in
the comment section. I will be happy to help you further.
Thanks
Get Answers For Free
Most questions answered within 1 hours.