Computer Science, asked by MasterQuestioner, 1 year ago

Write a program to input the Selling Price and Cost Price of a commodity and find the Profit or
Loss made upon selling the product.
For example,
INPUT:
Enter the Selling Price of the commodity: 456
Enter the Cost Price of the commodity: 400
OUTPUT:
Profit: 56

Answers

Answered by duragpalsingh
31

Hey there!

The program is as follows:

import java.util.*;

public class Question

{

static void main()

{

Scanner sc=new Scanner(System.in);

float sp,cp,profit=0,loss=0;

System.out.print("Enter the Selling Price of the commodity: ");

sp=sc.nextFloat();

System.out.print("Enter the Cost Price of the commodity: ");

cp=sc.nextFloat();

if(sp>cp)

{

profit=sp-cp;

System.out.println("Profit:"+profit);

}

else if(cp>sp)

{

loss=cp-sp;

System.out.println("Profit:"+loss);

}

else

System.out.println("No profit or gain");

}

}

Hope It Helps You!

Answered by siddhartharao77
19

Sample Program:

import java.util.*;

class Product

{

public static void main(String args[])

{

float SP, CP, Profit, Loss;

Scanner demo = new Scanner(System.in);

System.out.println("Enter Selling price of product: ");

SP = demo.nextFloat();

System.out.println("Enter Cost price of product: ");

CP = demo.nextFloat();

if(SP > CP)

{

Profit = SP - CP;

System.out.println("The profit he made is: " +Profit);

}

else if(CP > SP)

{

Loss = CP - SP;

System.out.println("The loss he suffered is: " +Loss);

}

else

{

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

}

}

}

Output:

Enter Selling price of product:

456

Enter Cost price of product:

400

The Profit he made is: 56.0

Hope it helps!


khushi5259: Wish You a Very Very Happy Birthday Dear ❤☺
siddhartharao77: Thank you so much
khushi5259: ^_^"☺✌
Similar questions