# Program to calculate Profit or Loss percentages using java

In calculating profit percent(%) and loss percent(%) we will learn about the basic concepts of profit and loss

Cost Price(C.P):

The price, at which an article(product) is purchased, is called its cost price(C.P)( how much the item cost the shop owner.)

Selling Price(S.P):

The price, at which an article(product) is sold, is called its selling prices(S.P).( what he is selling it for.)

Profit or Gain:

If Selling Price(S.P) is greater than Cost Price( C.P), the seller is said to have a profit or gain.

Loss:

If Selling Price(S.P) is less than Cost Price(C.P) the seller is said to have incurred a loss.

IMPORTANT FORMULAE

1. Gain = (S.P.) - (C.P.)
2. Loss = (C.P.) - (S.P.)

Example....

class ProfitLoss

{

public static void main(String aa[])

{

float CP,SP,profit, loss,profitper,lossper;

CP=1500;SP=1750;

if(SP>CP)

{

profit=SP-CP;

profitper=(profit/CP)*100;

System.out.println("Profit is="+profit);

System.out.println("Profit percentage is"+profitper+"%");

}

else if(CP>SP)

{

loss=CP-SP;

lossper=(loss/CP)*100;

System.out.println("Loss is="+loss);

System.out.println("Loss percentage is"+lossper+"%");

}

else

{

System.out.println("No Profit, No Loss");

}

// it is better to block the last else statement

//instead of let it as a single statement even

//though there will not be any syntax error.

}

}

Explanationâ€¦.

The if-else statement can be connected to more if-else or if statement to form a chain of if statements. This is called concatenating if-else-if. Any one of the block will be executed and never all of them.

Syntax:

If(condition)

Statement;

Else if(condition)

Statement;

Else

Statement;