-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.java
More file actions
139 lines (119 loc) · 4.97 KB
/
operators.java
File metadata and controls
139 lines (119 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
public class operators {
public static void main(String args[]){
// typecasting : forcefully conversion of one datatype to another is called typecasting
// typecasting : forcefully conversion of one datatype to another is called typecasting
System.out.println("sum of int and float integer");
float a = 10.56f;
int n = 20;
int b = (int)(a+n);
System.out.println(b);
System.out.println("product of long and short");
long f=45;
short g = 564;
float i=(int)(f*g);
System.out.println(i);
System.out.println("the subtraction of float and char");
float s = 90.4f;
char q = 'n';
float r = (char)(q-s);
System.out.println((int)(q));
System.out.println(r);
/*typepromotion in expression
1. java automatically promotes each byte short or char operand to int when evaluting an expression
2. if onr operand is long , float , double the whole expression promoted to long float or double respectively.*/
System.out.println("typepromotion of elements");
char z ='r';
char x = 'n';
System.out.println((int)(z));
System.out.println((float)(x));
System.out.println(x/z);
// operators in java:
/* symbol that tell compiler to perform some operation on operands
* type of operator are:*/
// 1. arthimetic operator:
// binary operator
int v = 22;
int w = 33;
System.out.println("add: "+v+w);
System.out.println("sub: "+ (w-v));
System.out.println("product: "+(w*v));
System.out.println("divide: "+(w/v));
System.out.println("modulo: "+ (w%v));
// unary operator:
System.out.println("pre increment");
System.out.println(++v); //pre increment-value change then value use.
System.out.println(++w);
System.out.println("post increment:");
System.out.println(v++); // post increment- value use then use
System.out.println(w++);
System.out.println("pre decrement: ");
System.out.println(--v);
System.out.println(--w); //pre decrement-value change then value use.
System.out.println("post decrement: ");
System.out.println(v--);
System.out.println(w--); //post decrement-value change then value use.
//relational operator
System.out.println(v==w);
System.out.println(v!=w);
System.out.println(v>w);
System.out.println(v<w);
System.out.println(v>=w);
System.out.println(v<=w);
// assignment operator
v+=w;
System.out.println(v);
v-=w;
System.out.println(v);
v*=w;
System.out.println(v);
v/=w;
System.out.println(v);
// bitwise operator: these are also exit in the operator.
//que1: in a program input 3 number : A,B and C ypu have to output the average these 3 number
int m= 34;
int p = 45;
int c = 99;
int avg= (m+p+c)/3;
System.out.println("average:"+avg);
//ques2: in program ,input the side of square you have to output the area of the square
int side= 5;
int area= side*side;
System.out.println("area:"+area);
//ques3: enter cost of 3 iteam from the user in a float a pencil, a pen ,ans an eraser. you have to output the total cost of the iteam back to the user as the bill.
float pen =5.0f;
float pencil=4.0f;
float eraser = 6.0f;
int sumation = (int)(pen + pencil + eraser);
System.out.println("sum of stationary:"+sumation);
// find the area of the triangle
int B= 10;
float h =20.8f;
float areaOfTriangle = (B*h)/2;
System.out.println("area of triangle: "+areaOfTriangle);
int sideA= 5;
int sideB =6;
int sideC= 8;
int parameterside=(sideA+sideB+sideC)/2;
double areaoftriangle =Math.sqrt(parameterside*(parameterside - sideA)*( parameterside - side)*(parameterside - sideC));
System.out.println("area of anothe triangle"+areaoftriangle);
// this is the root of the quadratic equation:
int a1, b1,c1;
a1=1;
b1=-4;
c1=4;
double r1,r2;
r1 =((-b1)+Math.sqrt((b1*b1)-4*a1*c1))/(2*a1);
r2=((-b1)-Math.sqrt((b1*b1)-4*a1*c1))/(2*a1);
System.out.println("the root of quadratic equation is: "+r1+" "+r2);
// printing the cuboid
int length=2;
int breadth =3;
int height =4;
int areaOfRectangle =length*breadth;
System.out.println("area of rectangle: "+ areaOfRectangle);
int parameterOfrectangle =2*(length*breadth);
System.out.println("parameter of rectangle: "+ parameterOfrectangle);
int volumeOfCuboid =length*breadth*height;
System.out.println("volume of cuboid: "+ volumeOfCuboid);
}
}