Operators 1 (2)
Operators 1 (2)
Operators
Level-1
TOTAL=50MARKS(18+32)
PART-A(18*1=18)
class Test {
public static void main(String args[]) {
int x = -4;
System.out.println(x>>1);
int y = 4;
System.out.println(y>>1);
}
}
class Test {
public static void main(String args[]) {
System.out.println(10 + 20 + "GeeksQuiz");
System.out.println("GeeksQuiz" + 10 + 20);
}
}
1. instanceof
2. sizeof
3. new
4. >>>=
class Base {}
class Derived extends Base {
public static void main(String args[]){
Base a = new Derived();
System.out.println(a instanceof Derived);
}}
5. Predict the output of following Java Program
class Test
{
public static void main(String args[])
{
String s1 = "geeksquiz";
String s2 = "geeksquiz";
System.out.println("s1 == s2 is:" + s1 == s2);
}
}
class Test
{
boolean[] array = new boolean[3];
int count = 0;
void set(boolean[] arr, int x)
{
arr[x] = true;
count++;
}
void func()
{
if(array[0] && array[++count - 2] | array [count - 1])
count++;
System.out.println("count = " + count);
}
7. In Java, after executing the following code what are the values of x, y
and z?
(A) -
(B) +
(C) *
(A) |
(B) ^
(C) ~
(D) <->
(A) ()
(B) ++
(C) *
(D) >=
(A) ()
(B) *
(C) +
(D) ++
17. Which one of the following is Equality operator in Java?
(A) >=
(B) <=
(C) !=
(D) +=
if(++a==11 || ++a==12)
++a;
System.out.println(a);
}
}
(A) 13
(B) 12
(C) 11
(D) 10
PART-A(16*2=32)
1.Length and breadth of a rectangle are 5 and 7 respectively. Write a program to calculate the
area and perimeter of the rectangle.
2.Write a program to calculate the perimeter of a triangle having sides of length 2,3 and 5 units.
3.Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the
quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.
4.Now, solve the above 3rd question using assignment operators (eg. +=, -=, *=).
7.Assign values of variables 'a' and 'b' as 55 and 70 respectively and then check if both the
conditions 'a < 50' and 'a < b' are true.
8.Now solve the above question to check if atleast one of the conditions 'a < 50' or 'a < b' is true.
9.If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a
program to calculate his total marks and percentage marks.
10.Suppose the values of variables 'a' and 'b' are 6 and 8 respecrtively, write two programs to
swap the values of the two variables.
1 - first program by using a third variable
2 - second program without using any third variable
( Swapping means interchanging the values of the two variables E.g.- If entered value of x is 5
and y is 10 then after swapping the value of x and y should become 10 and 5 respectively.)
12.The total number of students in a class are 90 out of which 45 are boys. If 50% of the total
students secured grade 'A' out of which 20 are boys, then write a program to calculate the total
number of girls getting grade 'A'.
13.Write a program to calculate the sum of the first and the second last digit of a 5 digit.
E.g.- NUMBER : 12345 OUTPUT : 1+4=5
14.Take a 4 digit number. Write a program to display a number whose digits are 2 greater than
the corresponding digits of the number TAKEN.
For example, if the number which was taken is 5696, then the displayed number should be 7818.