A shopkeeper sells two calculator for same price he on 20% profit on an one and suffered a loss of 20% on the other write a program in Java to find his total cost price of the calculator by taking selling prices input
Answers
Answer:
package com.sample.sample2;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double cp1,cp2,profit,loss;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the S.P of calculators");
double sp=scan.nextDouble();
double profitPercent=20,lossPercent=20;
/* formula for profit percent = profit/sp*100
* formula for loss percent = loss/sp*100
* where cp is cost price and sp is selling price
* profit=(profit percent *sp)/100
* loss=(loss percent *sp)/100
* hence by calculating profit and loss we can calculate cp*/
profit=(profitPercent*sp)/100;
loss=(lossPercent*sp)/100;
cp1=sp-profit;
cp2=sp+loss;
System.out.println("Cost price of Calculator which the shopkeeper sold on profit: \u20B9"+cp1+
"\nCost price of Calculator which the shopkeeper sold on loss: \u20B9"+cp2);
}
}
Explanation: the lines which are not bold are called comments and are neglected by the compiler.