write a program selling price and cost price of pen Calculate and display profit or loss its urgent please tell fast
Answers
Answered by
0
Answer:
import java.util.Scanner;
class Profit_Loss
{
public static void main(String[] args)
{
//Declaration
Scanner input = new Scanner(System.in);
double cp, sp, profit, loss;
//Prompt and accept the selling price and the cost price of the article
System.out.println("Enter the cost price of the article: ");
cp = input.nextDouble();
System.out.println("Enter the selling price of the article: ");
sp = input.nextDouble();
//Initialization
sp = 0.0;
cp = 0.0;
//Calculate the profit or the loss accordingly and display
if (cp > sp)
{
loss = cp - sp;
System.out.println("Loss suffered: " + loss);
}
if (sp > cp)
{
profit = sp - cp;
System.out.println("Profit earned: " + profit);
}
if (cp == sp)
{
System.out.println("No loss or gain.");
}
}
}
Similar questions