J.H.
TARAPORE SCHOOL
Computer Applications (Std X)
Worksheet 5 (2020-2021)
1. Explain three types of Mathematical Operators in Java with example. (Unary, Binary, Ternary)
2. Write the difference between Prefix and Postfix operators with example.
3. Write the difference between Postfix and Prefix decrement operators with example.
4. Explain Shorthand operator with example.
5. Explain Nested Ternary Operator with example.
6. Write the Java expression for the following :
𝑦 √𝑥 2 −3x
a) z= x3 + y2 - b) d =
2𝑥 a+b
7. Predict the output :
a. int c = ( 3 < 4 ) ? 3*4 : 3+4;
b. int a = 14, b=4;
boolean x =( a > b ) ? true : false;
c. int x = 90;
char c = (x<=90)? ‘Z’ : ‘I’;
d. int a = 18; int b = 12;
boolean t= (a>20 && b<15) : true: false;
e. c = ( val + 550 < 1700) ? 200 : 400;
if a) val = 1000 b) val = 1500
8. Write the difference between a) = and == b) / and % operator.
9. Rewrite the following segment using ternary statement.
a) if ( x%2 == 0) b) if(bill>10000)
[Link](“Even”); discount = bill * 10.0/100.0;
else else
[Link](“Odd”); discount = bill * 5.0/100.0;
10. Rewrite the following segment using if –else statement.
a) commission = (sale > 5000) ? sale * 10.0/100.0 : 0;
b) String grade = ( marks > 90)? “A”: (marks>=80)? “B” : “C”;
c) net = (salary > 10000) ? salary – (8.33/100)* salary : salary – (5/100) * salary;
d) c = (x >= ‘A’ && x<= ‘Z’) ? “Uppercase” : “Lowercase”;
e) s=(a+b<=c) || a+c<=b) || b+c<=a)? “ triangle is possible” : “triangle is not possible”;
(a=4, b=4,c=5)
11. Give the output of the following code.
a) a+= a++ + ++a + --a + a--; when int a = 11;
b) y+= ++y + y-- + --y; when int y = 9;
c) x = (++y * (y++ + 5); when y = 12;
d) int k=3, j=8; int k + = k++ - ++j + k; [Link]( k + “ “ + j);
[Link] SCHOOL
Computer Applications (Std X)
Worksheet 6 (2020-2021)
1. Write four features of Java.
2. Define Interpreter and Compiler.
3. What is a package?
4. Name the package that is imported by default.
5. Define Keyword or Reserved words in Java. Name five keywords which are commonly used.
6. Write the difference between [Link]() and [Link]() function.
7. Explain the significance of the following Java Library packages :
a) [Link] b) [Link] c) [Link]
8. Name the package where Scanner class is defined.
9. Write the syntax to create the object of the Scanner class.
10. Write the functions to be used to take input of following data type :
a) integer b) float c) double d) String e) char
11. What is an error in a program?
12. Explain Syntax error with an example.
13. Explain Logical error with an example.
14. Explain Runtime error with an example.
15. Write two differences between Syntax error and Logical error.
16. Write a program to input two unequal numbers. Display the numbers after swapping their
values in the variables without using a third variable.
Sample Input a = 10, b= 12
Sample Output a = 12, b= 10
17. The co-ordinates of two points A and B on a straight line are given as (x1, y1) and (x2,y2).
Write a program to calculate the slope (m) of the line by using formula.
𝑦2−𝑦1
Slope = 𝑥2−𝑥1
Take the co-ordinates (x1,y1) and (x2,y2) as input.