KnowledgeBoat Logo

Computer Applications

A shopkeeper sells two calculators for the same price. He earns 20% profit on one and suffers a loss of 20% on the other. Write a program to find his total cost price of the calculators by taking selling price as input.
Hint: CP = (SP / (1 + (profit / 100))) (when profit)
         CP = (SP / (1 - (loss / 100))) (when loss)

Java

Input in Java

142 Likes

Answer

import java.util.Scanner;

public class KboatShopkeeper
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the selling price: ");
        double sp = in.nextDouble();
        double cp1 = (sp / (1 + (20 / 100.0)));
        double cp2 = (sp / (1 - (20 / 100.0)));
        double totalCP = cp1 + cp2;
        System.out.println("Total Cost Price = " + totalCP);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A shopkeeper sells two calculators for the same price. He earns 20% profit on one and suffers a loss of 20% on the other. Write a program to find his total cost price of the calculators by taking selling price as input. Hint: CP = (SP / (1 + (profit / 100))) (when profit) CP = (SP / (1 - (loss / 100))) (when loss)

Answered By

52 Likes


Related Questions