Question #257434

Write a program in java to accept cost price and selling price of an article and find out loss or profit.

Expert's answer

import java.util.Scanner;


public class App {


	public static void main(String[] args) {


		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter cost price of an article: ");
		double costPrice = keyBoard.nextDouble();
		System.out.print("Enter selling price of an article: ");
		double sellingPrice = keyBoard.nextDouble();
		double diff = sellingPrice - costPrice;
		if (diff > 0) {
			System.out.println("Profit = " + diff);
		} else {
			System.out.println("Loss = " + Math.abs(diff));
		}
		keyBoard.close();


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS