Page 87 - CA_Blue( J )_Class9
P. 87
6 Scanner sc=new Scanner(System.in);
7 double cp,sp,p,pp;
8 System.out.print("Enter the cost price: ");
9 cp=sc.nextDouble();
10 System.out.print("Enter the selling price: ");
11 sp=sc.nextDouble();
12 p=sp-cp;
13 pp=p/cp*100.0;
14 System.out.println("Profit: "+p);
15 System.out.println("Profit Percentage: "+pp);
16 }
17 }
You will get the following output:
5.2 FORMS OF OPERATORS
In Java, there are mainly three forms of operators. Let us learn one by one in detail.
FORMS OF OPERATOR
UNARY BINARY TERNARY
5.2.1 Unary Operator
An operator that works with only one operand is called unary operator. For example, a++, --b.
Where, a and b are the operands, ++ and -- are the unary operators.
Operators in Java 85

