Answer to Question #257434 in Java | JSP | JSF for Sourav

Question #257434
Write a program in java to accept cost price and selling price of an article and find out loss or profit.
1
Expert's answer
2021-10-27T06:30:45-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS