Skip to content

Instantly share code, notes, and snippets.

@BT-ICD
Created January 24, 2021 17:36
Show Gist options
  • Save BT-ICD/8d7b5985ae4c37271f460a04f67b2636 to your computer and use it in GitHub Desktop.
Save BT-ICD/8d7b5985ae4c37271f460a04f67b2636 to your computer and use it in GitHub Desktop.
Example of conditional execution. To determine profit or loss. Calculate amount as well as percentage of profit or loss.
public class ProfitLossDemo {
public static void main(String[] args) {
double costPrice, salesPrice,profitAmt,lossAmt, profitPercentage, lossPercentage;
costPrice=50;
salesPrice=50;
if(costPrice>salesPrice){
lossAmt= costPrice-salesPrice;
lossPercentage=100*lossAmt/costPrice;
System.out.println("Loss in amount "+ lossAmt);
System.out.println("Loss in % " + lossPercentage);
}
else if(salesPrice>costPrice){
profitAmt= salesPrice-costPrice;
profitPercentage=100*profitAmt/costPrice;
System.out.println("Profit in amount " + profitAmt);
System.out.println("Profit in % " + profitPercentage);
}
else{
System.out.println("No profit no loss. Break even point");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment