Programming Examples

Java program to input selling price of 15 items and profit amount then find the cost price


If the total selling price of 15 items and the total profit earned on them is input through the

keyboard, write a program to find the cost price of one item.

Solution

import java.util.*;
class Price
{
	public static void main(String arr[])
	{
		Scanner sc=new Scanner(System.in);
		float tsp,tp,tcp,cp;
		System.out.println(“Enter the total selling price:”);
		tsp=sc.nextFloat();
		System.out.println(“Enter the total profit:”);
		tp=sc.nextFloat();
		tcp=tsp-tp; //total cost price
		cp=tcp/15; //cost price of one item
		System.out.println(“Cost Price of one item:”+cp);
	}
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad