REVIEW EXERCISES
1. What is meant by an IPO cycle?
Ans. Computer is a data processing machine that accepts data, processes it and
meaningful result. This complete operation of the computer is called Input
Output (IPO) cycle.
pPrroodcuesces
2. \What is meant by a user-frienly program?
Ans. Aprogram written in such a way that it makes other programmers or users to
logic of the program without much efort is known as a user-friendly program. follow
3. \What is a language translator? Give two examples.
Ans. Software that converts high-level language instructions into machine language instructie
to be understood by the computer is known as a language translator.
For example; Compiler and Interpreter.
4. What is the need of data type?
Ans. The system needs to know the optimum space required for storing the data efficiently
This is the reason, the data type needs to be mentioned before using the values.
5. Differentiate between literals and variables.
Ans. Literals are the constants that remain unchanged throughout the
execution of a program
A variable is used to store a specific type of literal. The value of a
variable can be changei
depending upon the circumstances or problems.
6. Distinguish between an operator and an
expression.
Ans. An operator is a symbol or a sign used to perform an
operation in the computer. An
expression is a combination of variables, literals and arithmetical operators.
7. Why should a keyword not be used as a variable?
Ans. Keyword is also called reserved word that carries special meaning for
the
used as a variable, then the normal functioning of the compiler will get compiler. If it is
affected.
8. Diferentiate between int and long data
type.
Ans. The int data type is used to represent a short range of integer
values, whereas, long data type
represents a long range of integer values.
What is the difference between I and %operators?
Ans. The 'P operator results in displaying the quotient (integer type), when two numbers are
divided.
For example, int a=3, b=7, c;
c=bla;
The output: c= 2
However, the '% operator results in displaying the remainder (integer type), when two
numbers are divided.
For example, int a=3, b=7, c;
c=b%a;
The output: c= 1
88 Computer Studies-8
il
be the output of k and j in the
What
int
k=5,j=9 following code?
ttj+ k;
tazktt -
j=10
k=6
an Java for 5x' +2y/(x + y).
expression in
Sx'x'x+2"y/(x+y)
onepointof difference
Give between unary and a single
Ink Unaryoperatoris used to perform operations onbinary
2
operators.
operand.
tta, --a, etc.
Eor exampe,
Binary operator performs operations on two operands.
(a + b), (a - b), etc.
Forexample,
aJava expression for u' + 2as.
u*u + 22*a*s
Javaexpression:
Ans.
will the result stored in xafter
H. What evaluating the following expression?
int x=4;
t=(X++) + (t+x) + x;
6) + 6= 20
Ans. 4 + (4 +
5. Write a Java expression for ut +
*
Ans. Java expression: u *t+1/2 * f*
16, Case-Study Based Questions:
Solved
1. In any programming language, we deal with variables to store different types of values.
Java language uses the data types such as int, float, char, double, string, etc. Therefore,
it is important for the programmer to know the types of data likely to be supplied for
storage. Some data values used in Java programming are given below:
(a) "Computer Studies for Class 8"
(b) 12.000045725
(c) T
(a) 55.25
Identify the data type of each of the above mentioned values.
Ans. (a) String (b) double (c) char (d) float
2. Prefix and postfix operators are very signiicant in Java programming. The prefix works
on the principle 'Change bejore the action' and the postfix on 'Change after the action.
Aprogram snippet using prefix and postfix operators is as given below:
int p=10,q=14;
[Link]("Result:" +p++); /lStatement 1
pt+;
[Link]("Result:"+p); // Statement 2
q=++q;
[Link]("Result:"+q); I/ Statement 3
[Link]("Result:"+(p++ + )); // Statement 4
89
Program Coding
on the above case, answer the lollowing questions:
Based
'Statement 1?
(a) What will be the result in
(ii) 1|
(iii) 12 (iv) 13
(i) 10
'Statenent 2?
(b) What will be the result in
(ii) 12 (iv) 25
() 10 (ii) ||
3?
() What will be the resul in 'Satement
(iii) 12 (iv) 15
() 10
(d) What will be the resul in 'Statement 4?
(ii) 27 (iii) 28 (iv) 29
Ans. (a) () 10 (b)(ii) 12 (c) (iv) 15 (d) (i) 27
EXERCISES
Objective
1. Choose the correct option:
1. Character literal is assigned to a:
(a) char variable (b) char type literal (c) string variable (d) string literal
2. A character literal is enclosed in:
(a) (b) » (c) :: (d) {}
3. A set of characters is assigned to a:
(a) String variable (b) Static variable (c) Char variable (d) None
4. The statement n += 4 is equivalent to:
(a) ++n (b) n=n+4 (c) n+1 (d) none
5. What will be the output of a++, if int a = -1;?
(a) 1 (b) -1 (c) 0 (d) none
6. If int a=25, b=5,c=0; what value is stored in c when c = a%b?
(a) 5.0 (b) 5 (c) 0 (d) none
7. What will be the result of m, in the expression m*=8 if
m=8;?
(a) 8 (b) 64 (c) 16 (d) 88
8. double c;
int x,y,z;
X=5; y=10; z=11;
C=x*y+z/2;
The value stored in c is:
(a) 55.0 (b) 55.5 (c) 55 (d) none
9. int m,p; m=5; p=0; p= m -- + -- m; The output will be:
(a) 11 (b) 10 (c) 8 (d) 12
10. int a=7, p=0, q-0;
p= ++a + --a;
q-= p; The output of q will be:
(a) 13 (b) 14 (c) 15 (d) -15
90 Computer Studies-8
willbe the output of a and 'b in the expression
(a)10,10 (b) 10,11 b=att, if int a, b; a-103
(c) 1,10 (d) 11,|
Salenhetherthe following statements are True or False:
[Link] known as an Object Oriented Programming
comment line of
the program is ignored
(OOP) language.
be same as the
during execution.
The data type must value assigned to the
[Link] value can be assigned to a double type [Link].
In' in
the statement [Link]. println( )
The letters directs the cursor
nnove to the next line after displaying the yalue.
6 The variables used in Java program are called reserved words.
Literals remain unchanged throughout the execution of a program.
&When an increment or decrement operator is used before the operand,
t is known as the postfx operator.
Write the Java expressions for the following:
1. ab + bc + ca 2. a + ab - b²
3. ut + 4. (a + b)3
5. 2(lb+bh+lh) 6. a + b²
[V. Predict the output:
1. lfm =5 and n = 2, predict the output values of mand n, when:
(a) m -= n; (b) n= m + m/n;
2. What will the output of the variable 'a'?
int a-0,b=10,c=40;
a =--b+ (c++) + b;
3. What will be the output of the following, if x=5 initially?
(a) 5*++x; (b) 5*x ++;
4. Evaluate the following expressions:
Ifthe values of the variables are a = 2, b = 3, and c =9.
(a) a - (b++)*(--c);
(b) a(++b)%c;
5. If a= 5, b= 9, calculate the value of a in the following expression:
a t= (a ++) - (++ b) +a
V. Case-Study Based Question:
Unsolved or
e logical operators are used in between two conditions, which results in either "True
ase depending on the outcome of different conditions. Java uses three logical operators
i AND, OR and NOT Your friend has created a Java snippet that contains some errors
91
Program Coding
due to which he is not able to cxecute it. Ihc program snippet crealed by
by him
below:
int p=l1, q-12, r5;
(a) [Link] ((p==) AND (q!-));
(b) [Link]((p=q))}:
(c) [Link] (p!=-);
(d) [Link] ((p!=q) OR (q!=r));
Refer to the above ssnipppet and help him by detecting the errors so that
the
execute successfully.
snippet ma
Subjective
I. Answer the following questions:
1. Define a
program.
2. What are the characteristics of a
program? Name them.
3. Who developed Java?
4. Java is case
sensitive. Explain.
5. Mention at least four
features of Java.
6. What is meant by Java
keywords? Explain.
7. How are data types
8.
classified?
Define the following:
(a) Variable
(b) Floating literal
(c) String literal (d) Character literal
9. Write down the data type of the
(a) Integer
following:
(c) A character
(b) Long Integer
(d) A fractional number
10. What is an operator? Name the
different types of operators.
11. State the difference between = and =
=.
12. What is meant by a constant? Explain
with an example.
13. What are the rules to be
followed to assign a variable in Java
14. Distinguish between the following: programming?
(a) Source code and Object code (b) Compiler and
15. Explain the following: lnterpreter
(a) Arithmetical operator (b) Relational operator
(c) Logical operator (d) Arithmetic expression
16. Differentiate between the
following:
(a) Arithmetical and Logical operator
(b) Logical AND (&&) and Logical OR (|)
(c) Prefix and Postfix operator
92 Computer Studies--8