WAP to input CP and SP and check profit or loss using scanner.

1 year ago
OOP Java

Compile code:

import java.util.Scanner;

public class Profit_or_loss{

    public static void main(String[]args)

    {

        float cp,sp,amt;

        Scanner s=new Scanner(System.in);

        System.out.println("Enter the cost price of the item:");

        cp=s. nextInt();

        System.out.println("Enter the sales price of the item:");

        sp=s. nextInt();

        if(sp>cp){ 

        amt=sp-cp;

        System.out.println("The profit amount=Rs.");

        }

        else if(cp>sp){

            amt=cp-sp;

            System.out.println("The loss amount=Rs.");

        }

        else

            System.out.println("There is neither profit nor loss");

    }

}

 

Output:

0
Dipti KC
Jan 8, 2023
More related questions

Questions Bank

View all Questions