Dremendo Tag Line

Check if the seller has made profit or not in Java

if else - Question 3

In this question, we will see how to input cost price and sale price and check if the seller has made a profit or not in Java programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q3) Write a program in Java to input cost price and sale price and check if seller has made profit or not.

Program

import java.util.Scanner;

public class Q3
{
    public static void main(String args[])
    {
        int cp,sp;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter cost price ");
        cp=sc.nextInt();
        System.out.print("Enter sale price ");
        sp=sc.nextInt();
        if(sp>cp)
        {
            System.out.print("The seller has made a profit");
        }
        else
        {
            System.out.print("The seller has not made any profit");
        }
    }
}

Output

Enter cost price 350
Enter sale price 465
The seller has made a profit
video-poster