What will be the output of the following program segments?
i. int a = 0;
if ( a>0 && a<20 )
a++;
else a -- ;
System.out.println (a);
ii. int a =5, b= 2, c;
if ( a>b || a!=b)
c = ++ a + --b;
System.out.print(c+ “ “ +a+ “ “+b);
Answers
Answer:
Question 1
The statement n += 4 is equivalent to:
++n
n=n+4 ✓
n+1
none
Question 2
What will be the output of a & b in the following, if int a, b; a=10; b=a++;
10,10
10,11
11,10 ✓
11,11
Question 3
What will be the output of a++ when int a = -1;
1
-1
0 ✓
none
Question 4
If int a = 25, b = 5, c = 0; what value is stored in c? When c = a % b;
5.0
5
0 ✓
none
Question 5
What is the result of the following in Java statement?
int m=8;
m*=8;
System.out.println("The output =" + m);
8
64 ✓
16
88
Question 6
double c;
int x, y, z;
x = 5; y = 10; z = 11;
c = x*y+z/2;
The value stored in c is:
55.0 ✓
55.5
55
none
Explanation
c = x * y + z / 2
⇒ c = 5 * 10 + 11 / 2
⇒ c = 5 * 10 + 5
⇒ c = 50 + 5
⇒ c = 55.0
Question 7
int m, p;
m = 5;
p = 0;
p = m-- + --m;
The output will be:
11
10
8 ✓
12
Explanation
p = m-- + --m;
⇒ p = 5 + 3
⇒ p = 8
Question 8
int a=7, p=0, q=0;
p= ++a + --a;
q -= p;
The output of q will be:
13
14
15
-15 ✓
Explanation
p = ++a + --a
⇒ p = 8 + 7
⇒ p = 15
q -= p
⇒ q = q - p
⇒ q = 0 - 15
⇒ q = -15
Write the Java expressions for the following:
Question 1
p = a2 + bc
Answer
p = a * a + b * c
Question 2
m = a2 - b2 / (ab)
Answer
m = (a * a - b * b) / (a * b)
Question 3
s = ut + (1/2)at2
Answer
s = u * t + (1.0 / 2) * a * t * t
Question 4
f = uv / (u + v)
Answer
f = u * v / (u + v)
Question 5
(a + b)2 + b
Answer
(a + b) * (a + b) + b
Question 6
y = 2(lb + bh + lh)
Answer
y = 2 * (l * b + b * h + l * h)
Question 7
a2 + b2
Answer
a * a + b * b
Question 8
z = x3 + y3 - xy / 3
Answer
z = x * x * x + y * y * y - x * y / 3
Answer the following questions
Question 1
What is an operator?
An operator is a symbol or sign used to specify an operation to be performed in Java programming.
Answer:
-1 is the correct answer
please mark me the brainliest