Coding Practice

Write a Java program to calculate profit or loss

Calculate profit or loss
Sample Output
Calculate profit or loss.

Purchase Price: 7
Selling Price: 9
Profit!
Java-Source Code
//package ifelsejava;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int buy, sell;

        Scanner input = new Scanner(System.in);

        System.out.println("Calculate profit or loss.\n");

        System.out.print("Purchase Price: ");
        buy = input.nextInt();

        System.out.print("Selling Price: ");
        sell = input.nextInt();

        if (buy < sell) {
            System.out.println("Profit!");
            
        } else if (sell == buy) {
            System.out.println("No Loss No Profit.");
        
        } else {
            System.out.println("Loss!");
        
        }
    }
}
Sample Output
Calculate profit or loss.

Purchase Price: 100
Selling Price: 90
Loss!

No comments:

Post a Comment

Change Theme
X