JAVA
Operator
Fill
in the blanks
1.
% symbol what will return remainder
2.
++ operator means increment
operator
3.
- - means decrement operator
4.
Write logical NOT operator !
5.
Write logical AND operator &&
6.
Write Bitwise 1’s complement operator
~
7.
Write Bitwise OR operator |
8.
Write Bitwise X-OR operator ^
9.
Write Bitwise left shift operator <<
10.
Write Bitwise right shift operator >>
11.
Write Concatenation operator +
Answer
the Following Questions
(4
marks)
1.Write a program for Arithmetic
Operator
class ArithmeticTest{
public static void main (String args[]){
short x=6;
int y=4;
float a=12.5f;
float b=7f;
System.out.println("x
is"+x+",y is"+y);
System.out.println("x+y="+(x+y));
System.out.println("x-y="+(x-y));
System.out.println("x*y="+(x*y));
System.out.println("x/y="+(x/y));
System.out.println("x%y="+(x%y));
System.out.println ("a
is"+a+"b is"+b);
System.out.println("a/b="+(a/b));
}
}
2.Write a program for Bitwise Operator
class BitwiseDemo
{
public static void main(String args[])
{
int x=10;
int y=20;
int z=30;
x=x | 40;
y>>=1;
z<<=2;
System.out.println("x | 40 :"
+x);
System.out.println("y>>1
:" +y);
System.out.println("z<<2
:" +z);
// reinitialize to its original value.
x=10;
z=30;
x=x^z;
System.out.println("x^z:" +z);
}
}
3. Write a program for Logical
Operator
class Logical{
public static void main (String args[]){
int x=6;
int y=4;
System.out.println((x==6)&&(y==3));
System.out.println((x==6)||(y==3));
System.out.println(!(x<y));
}
}
4. Write a program for Relational
Operator
class Comparison{
public static void main (String args[]){
int x=6;
int y=4;
System.out.println("x
is"+x+",y is"+y);
System.out.println("x<y="+(x<y));
System.out.println("x<=y="+(x<=y));
System.out.println("x>y="+(x>=y));
System.out.println("x==y="+(x==y));
System.out.println("x!=y="+(x!=y));
}
}
5.Write a program for Conditional
Operator
class ConOprDemo
{
public static void main (String args[])
{
int x=25;
int y=10;
int z=0;
//The smaller value is returned
z=x>y?x:y;
System.out.println("The value
is"+z);
}
}
Answer
the Following Questions
(10
marks)
1.What is Operator? Write 8 Operator.
Arithmetic Operator:
class ArithmeticTest{
public static void main (String
args[]){
short x=6;
int y=4;
float a=12.5f;
float b=7f;
System.out.println("x
is"+x+",y is"+y);
System.out.println("x+y="+(x+y));
System.out.println("x-y="+(x-y));
System.out.println("x*y="+(x*y));
System.out.println("x/y="+(x/y));
System.out.println("x%y="+(x%y));
System.out.println ("a
is"+a+"b is"+b);
System.out.println("a/b="+(a/b));
}
}
Assignment
Operators:
class AssignDemo{
public static void main
(String args[]){
int a=1;
int b=2;
int c=3;
a+=5;
b*=4;
c+=a*b;
c%=6;
System.
out.println("a="+a);
System.
out.println("b="+b);
System.
out.println("c="+c);
}
}
Incrementing
and Decrementing :
class PrePostFixTest{
public static void main(String
args[]){
int x=10;
System.out.println("-------------------------------------------");
System.out.println("Initial value of X:"+x);
System.out.println("X value in Println:"+x++);
System.out.println("After Post increment X:"+x);
System.out.println("-------------------------------------------");
x=10;
System.out.println("Initial value of X:"+x);
System.out.println("X value in Println:"+ ++x);
System.out.println("After Post increment X:"+x);
System.out.println("-------------------------------------------");
}
}
Comparisons Or Relational
Operator
class Comparison{
public static void main (String args[]){
int x=6;
int y=4;
System.out.println("x
is"+x+",y is"+y);
System.out.println("x<y="+(x<y));
System.out.println("x<=y="+(x<=y));
System.out.println("x>y="+(x>=y));
System.out.println("x==y="+(x==y));
System.out.println("x!=y="+(x!=y));
}
}
Logical
Operator
class Logical{
public static void main (String args[]){
int x=6;
int y=4;
System.out.println((x==6)&&(y==3));
System.out.println((x==6)||(y==3));
System.out.println(!(x<y));
}
}
Bitwise
Operator
class BitwiseDemo
{
public static void main(String
args[])
{
int x=10;
int y=20;
int z=30;
x=x | 40;
y>>=1;
z<<=2;
System.out.println("x | 40
:" +x);
System.out.println("y>>1
:" +y);
System.out.println("z<<2
:" +z);
// reinitialize to its original value.
x=10;
z=30;
x=x^z;
System.out.println("x^z:"
+z);
}
}
String-concatenation
operator
Concatenation operator (+)
system.out.println("I"+"love"+"BGMI");
output of the above line is : I love
BGMI
class Concatenation{
public static void main(String
args[]){
System.out.println("I
"+" love "+" India ");
}
}
No comments:
Post a Comment