0% found this document useful (0 votes)
2 views80 pages

MCQ1 2 Operators

The document contains a series of Java code snippets along with their expected outputs, covering various operators and expressions. It includes examples of comparison, arithmetic, bitwise operations, and the use of the ternary operator. Additionally, it addresses common compilation errors and clarifies the behavior of certain operations in Java.

Uploaded by

Sampurna prusty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views80 pages

MCQ1 2 Operators

The document contains a series of Java code snippets along with their expected outputs, covering various operators and expressions. It includes examples of comparison, arithmetic, bitwise operations, and the use of the ternary operator. Additionally, it addresses common compilation errors and clarifies the behavior of certain operations in Java.

Uploaded by

Sampurna prusty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

Operators

1. Find output
System.out.println(3<4);
System.out.println(3<=4);
System.out.println(3>4);
System.out.println(3>=4);
System.out.println(3==4);
System.out.println(3!=4);
Output
true
true
false
false
false
true
2 Find output
System.out.println(9/5);
System.out.println((float)9/5);
System.out.println(9/(float)5);
System.out.println((float)(9/5));
Output
1
1.8
1.8
1.0
3 Find output
int var = 65;
char ch = (char)var;
System.out.println(var);
System.out.println(ch);
Output
65
A
4 Find output
System.out.println(6%2==0);
System.out.println(7%2!=0);
Output
true
true
5 Find output
int a=3,b=6;
b=a+b-(a=b);
System.out.println(a+","+b);
Output
6,3
6 Find output
System.out.println(5/2);
System.out.println(-5/2);
System.out.println(5/-2);
System.out.println(-5/-2);

System.out.println(5%2);
System.out.println(-5%2);
System.out.println(5%-2);
System.out.println(-5%-2);
Output
2
-2
-2
2
1
-1
1
-1
7 Find output
int a=2,b=3,c=1;
System.out.println(a+b+c);
System.out.println("sum="+a+b+c);
System.out.println(a+b+c+"sum="+a+b+c);
System.out.println(a+b+c+"sum="+(a+b+c));
Output
6
sum=231
6sum=231
6sum=6
8 Find output
int a,b,c,d;
c=10;
d=a=b=c;
System.out.println(a+","+b+","+c+","+d);
Output
10,10,10,10
9 Find output
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
Output
1
10 Find output
int a =5,b;
b = ++a + a++ + ++a;
System.out.println(a);
System.out.println(b);
Output
8
20
11 Find output
int a=3,b=4,c;
c=++a + b++ + ++a + --b;
System.out.println(c);
Output
17
12 Find output
int x = -16;
System.out.println(x>>2);
int y = 4;
System.out.println(y>>1);
Output
-4
2
13 Find output
String s1 = "raju";
String s2 = "raju";
System.out.println("s1 == s2 is:" + s1 == s2);
Output
true
14 Find output
String s1 = "raju";
String s2 = "raju";
System.out.println("s1 & s2 are equal " +
s1.equals(s2));
Output
s1 & s2 are equal true
15 Find output
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b);
Output
5.640000000000001 5
16 Find output
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c);
Output
3 4 4
17 Find output
int a,b,c;
a=b=c=10;
System.out.println(a+b+c);
System.out.println(a+""+b+c);
System.out.println(a+b+""+c);
System.out.println(""+a+b+c);
Output
30
101010
2010
101010
18 Find output
int (a,b,c)=10;
System.out.println(b);
Output
• Compilation error
19 Find output
byte b1 = 6 & 8;
byte b2 = 7 | 9;
byte b3 = 5 ^ 4;
System.out.println(b1 + " " + b2 + " " + b3);
Output
0 15 1
20 Find output
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2);
System.out.print(i + " " + y);
Output
256 0
21 Find Output
byte a=3, b=7,c;
c=a+b;
Output
• Compile time error
22 Find Output
byte a=3,b=7;
int c;
c=a+b;
System.out.println(c);
Output
• 10
23 Find Output
int a = 1, b=20, c=15,d;
d= a>b? a>c?a:c : b>c?b:c;
System.out.println(d);
Output
• 20
24 Find Output
byte a=8,b;
b=a<<2;
System.out.println(b);
Output
• Compilation error
25 Find Output
byte a=8;
int b;
b=a<<2;
System.out.println(b);
Output
• 32
26 Find Output
byte a=8;
byte b=2;
b+=a;
System.out.println(b);
Output
• 10

• Because we applied += (assignment


opearator)
27 Find Output
byte a=8;
byte b=0;
b=a&b;
System.out.println(b);
Output
• Compilation error
• When ever we apply any arithmetic or bitwise
operators on 2 byte values, the result will be
integer.
28 Find Output
int x = -4;
System.out.print(x>>1+” “);
int y = 4;
System.out.print(y>>1);
a) Compiler Error
b) -2 2
c) 2 2
d) 0 2
Output
B
29 Find Output
System.out.println(10*20 + “raju");
System.out.println(“rani" + 10*20);
a) 200raju
rani200
b) Compilation error
c) 10*20 + “raju“
“rani" + 10*20
d) No output
Output
A
30 Find Output
Which of the following is not an operator in
Java?
(A) instanceof
(B) sizeof
(C) new
(D) >>>
Output
B
31 Find Output
System.out.println(10+20 +"raju"+10+20);
a) 1020raju1020
b) 30raju1020
c) 1020raju30
d) 10+20 +"raju"+10+20
Output
B
32 Find Output
Which of these operators can skip evaluating
right hand operand?
A. !
B. |
C. &
D. &&
Output
• D
33 Find Output
Which of these statement is correct?
A. true and false are numeric values 1 and 0
B. true and false are numeric values 0 and 1
C. true is any non zero value and false is 0
D. true and false are non numeric values
Output
D
34 Find Output
What should be expression1 evaluate to in using
ternary operator as in this line? expression1 ?
expression2 : expression3
A. Integer
B. Floating – point numbers
C. Boolean
D. None of the mentioned
Output
C
35 Find Output
What is the value stored in x in following lines of
code?int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0
b) 1
c) 9
d) 8
Output
D
36 Find Output
Modulus operator, %, can be applied to which of
these?
A. Integers
B. Floating – point numbers
C. Both Integers and floating – point numbers
D. None of the mentioned
Output
C
37 Find Output
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b);
Output
a) 5.640000000000001 5
b) 5.640000000000001 5.0
c) 5 5
d) Compilation error

Ans: a
38 Find Output
System.out.println(23.45%10);
a) 3.4499999999999993
b) 5
c) 0.005
d) 23
Output
A
39 Find Output
int x , y;
x = 10; Options
x++; A. 11 11
B. 10 10
--x; C. 11 10
y = x++; D. 10 11
System.out.println(x + " " + y);
Output
C

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy