20.04.23 IX A Computer
20.04.23 IX A Computer
Dear students, write the following work in your copies and try to solve the remaining
questions too.
Q. Write the Java expressions for the following:-
1. s=ut+21at2
Ans: s = u * t + (1 / 2) * a * t * t
2. z=x3+y3−zxy
Ans: z = x * x * x + y * y * y - x * y / z
ii. n = m + m/n
->n = 5 + 5/2
->n = 5 + 2
-> n = 7
2. What will be the output for the following program segment?
int a=0,b=10,c=40;
a = --b + c++ +b;
System.out.println(" a = " + a);
Ans: a = 58
Method:-
a = --b + c++ + b
->a = 9 + 40 + 9
-> a = 58
3. Give the output of the program snippet.
int a = 10, b =12;
if(a>=10)
a++;
else
++b;
System.out.println(" a = " + a + " and b = " +b);
Ans: a = 11 and b = 12
Method:-
The condition if(a>=10) is true so a++ increments a to 11. b remains the same.
4. Rewrite the following using ternary operator.
if(income<=100000)
tax = 0;
else
tax = (0.1*income);
Ans: tax = income <= 100000 ? 0 : (0.1*income);
1. Write a program to find and display the value of the given expression:
(x + 3) / 6 - (2x + 5) / 3;
4. The normal temperature of human body is 98.6°F. Write a program to convert the
temperature into degree Celsius and display the output.
Hint: c / 5 = f - 32 / 9