Created
January 24, 2021 17:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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