-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofitloss.java
More file actions
27 lines (20 loc) · 794 Bytes
/
Copy pathprofitloss.java
File metadata and controls
27 lines (20 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//this program calculates profit/loss based on selling price
import java.util.Scanner;
public class profitloss{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter purchasing rate: ");
double purchasingRate = scanner.nextDouble();
System.out.print("Enter selling rate: ");
double sellingRate = scanner.nextDouble();
double profitOrLoss = sellingRate - purchasingRate;
if (profitOrLoss > 0) {
System.out.println("Profit: " + profitOrLoss);
} else if (profitOrLoss < 0) {
System.out.println("Loss: " + Math.abs(profitOrLoss));
} else {
System.out.println("No profit, no loss.");
}
scanner.close();
}
}