Computer Science, asked by iamlightningboy, 3 months ago

write a java program to input the cost price and selling price of a car and check wether it is profit or loss.​

Answers

Answered by BrainlyProgrammer
6

Answer:

//Program to calculate Profit or loss

package Programmer;

public class Profit{

public static void main (String ar []){

Scanner sc=new Scanner (System.in);

System.out.println("Enter SP and CP of a car");

double SP=sc.nextDouble();

double CP=sc.nextDouble();

if(CP>SP)

System.out.println("Loss:"+ (CP-SP));

else

System.out.println("Profit:"+(SP-CP));

}

}

_____

Variable Description:-

  • SP:- to accept the selling price
  • CP:- to accept the cost price

____

Explaination:-

  • The program accepts SP and CP of a car and store them in variables SP and CP respectively.
  • If CP > SP then loss
  • else it is profit
  • it also prints the loss/profit.

_

Answered by DüllStâr
52

Using scanner class :-

import java.util.*;

class Profit_Loss

{

public static void mean(String[]args)

{

Scanner sc = new scanner (System.in);

int cp , sp;

System.out.println("Enter value of Cost Price");

cp =sc.nextInt();

System.out.println("Enter value of Selling Price");

sp = sc.nextInt();

if(cp>sp)

int loss = cp - sp;

System.out.println("Person made loss of : Rs" + loss);

else

int profit = sp - cp;

System.out.println("Person made profit of : Rs" + profit);

}

}

Using InputStreamReader Class :-

import java.util.*;

class Profit_Loss

{

public static void main (Sting[]args)throws IOException

InputStreamReader read = new InputStreamReader (System.in);

BufferReader in = new BufferReader(read);

int cp , sp;

System.out.println("Enter value of Cost Price");

cp =Int.phraseInt(in.readLine());

System.out.println("Enter value of Selling Price");

sp = Int.phraseInt(in.readLine());

if(cp>sp)

int loss = cp - sp;

System.out.println("Person made loss of : Rs" + loss);

else

int profit = sp - cp;

System.out.println("Person made profit of : Rs" + profit);

}

}

Input:-

Enter value of Cost Price

2100

Enter value of Selling Price

3100

Output:-

Enter value of Cost Price

2100

Enter value of Selling Price

3100

Person made profit of : Rs 1000

Similar questions
Math, 9 months ago