[Solved] Calculating Gain Percentage with Java

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

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.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *