bluej Programs
4.Write a program that will enter cost amount and selling amount. Calculate the profit or loss occurred .
import java.util.*;
class ProfitLoss
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Cost Price:");
int cp=sc.nextInt();
System.out.println("Enter the Selling Price:");
int sp=sc.nextInt();
if(cp>sp)
System.out.println("Loss");
else if(sp>cp)
System.out.println("Profit");
else
System.out.println("No Profit No Loss");
}
}
Output:
Enter the Cost Price: 678 Enter the Selling Price: 876 Profit
ADVERTISEMENT
