Computer Science, asked by raipintu2007, 7 months ago

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 in java to find his total cost price of the calculators by

taking selling price as input.​

Answers

Answered by dxb4637020
9

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.

Similar questions