Calculating Gain Percentage: Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , what is his gain %?![[Solved] Calculating Gain Percentage with Java [Solved] Calculating Gain Percentage with Java](https://app.e-box.co.in/uploads/Image/scooter.jpg)
Write a program to compute the gain %.
Input Format:
The first input is an integer which corresponds to A. The second input is an integer which corresponds to B. The third input is a float which corresponds to gain %.
Output Format:
Refer sample input and output for formatting specifications.
The float values are displayed correct to 2 decimal places.
Sample Input
4700 800 5800
Sample Output:
5.45
Solution
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int a, b, c;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
System.out.printf("%.2f", ((c-a-b)*1.0/(a+b))*100);
}
}
Happy Learning – If you require any further information, feel free to contact me.
![[Solved] Calculating Gain Percentage with Java [Solved] Calculating Gain Percentage with Java](https://realcoder.techss24.com/wp-content/uploads/2022/10/Solved-Calculating-Gain-Percentage-with-Java.png)
![[Solved] Best Couple Event with Java, C++, Python](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Best-Couple-Event-with-Java-C-Python-300x200.png)
![[Solved] Sum of Odd and Even Digits with Java, C++, Python](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Sum-of-Odd-and-Even-Digits-with-Java-C-Python-300x200.png)
![[Solved] Exception Handling with Java](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Exception-Handling-with-Java-300x200.png)