import java.util.Scanner; public class Profit { public static void main(String[] args) { double c,s,p,l ; Scanner in = new Scanner(System.in); System.out.println("Enter CP"); c = in.nextDouble(); System.out.println("Enter Sp"); s = in.nextDouble(); if(c<s) { p = (s - c); System.out.println("Profit=" + p); } else if (c>s){ System.out.println("Loss=" + (c-s)); } else { System.out.println ("There is no loss or gain.") } } }
Answers & Comments
Your answer-
import java.util.Scanner;
public class Profit
{
public static void main(String[] args) {
double c,s,p,l ;
Scanner in = new Scanner(System.in);
System.out.println("Enter CP");
c = in.nextDouble();
System.out.println("Enter Sp");
s = in.nextDouble();
if(c<s) {
p = (s - c);
System.out.println("Profit=" + p);
}
else if (c>s){
System.out.println("Loss=" + (c-s));
} else {
System.out.println ("There is no loss or gain.")
}
}
}
Hope it helps:)