Page 97 - 2617_JSSPS_C-7
P. 97
Arithmetic Statement: When the expression is assigned to a variable, then it is called Arithmetic
Statement.
Example: c=a*b, p=2*(l + b)
Mathematical Expression Java Expression
a+bc a+b*c
2
a +b 2 a*a+b*b
prt (p*r*t)/100.0
100
1 (u*t) + (1.0/2.0*a*t*t)
ut+ at 2
2
ad + bc (a*d+b*c)/(b*d)
bd
2πr 2 2*(22.0/7.0)*r*r
ab+bc+ca a*b+b*c+c*a
(m+n)(n+k) (m+n)*(n+k)
Program 2: Write a program to display the use of operators.
1 import java.util.*;
2 class operators
3 {
4 public static void main(String args[])
5 {
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 }
Java Programming 95

