Generally, a computer language uses either compiler or interpreter (a set of programs) to convert source code into object code. But Java, a case sensitive language, uses both the translators (i.e., compiler as well as interpreter). Firstly, compiler converts the Java source code into an intermediate code which is further converted into machine code with the help of an interpreter.

Based on the above discussion, answer the following questions:

(a) Which of the following statement is true?

- Java compiler is a hardware.
- Java compiler is a software but interpreter is a hardware.
- Both the translators are hardware.
- Both the translators are software.

(b) The intermediate code is referred to as:

- Byte code
- Assembly code
- ASCII code
- Unicode

(c) Java interpreter is also known as:

- Artificial machine
- Virtual machine
- Real machine
- Normal machine

(d) What is meant by a case sensitive language?

- It understands only lowercase letters.
- It understands only uppercase letters.
- It distinguishes between lowercase and uppercase letters.
- It doesn't distinguish between lowercase and uppercase letters.

**Answer**

(a) Both the translators are software.

(b) Byte code

(c) Virtual machine

(d) It distinguishes between lowercase and uppercase letters.

An operator is basically a symbol which performs arithmetical and logical operations to yield meaningful results. There are three types of operators used to perform any operation in Java programming. They are arithmetical, relational and logical operators. The arithmetical operators are used to perform arithmetical calculations. They are unary, binary and ternary operators. The syntax of using ternary operator is:

```
variable = (condition) ? expression 1 : expression 2;
```

Based on the above discussion, answer the following questions:

(a) A/An ............... operator works on a single operand.

- binary
- relational
- unary
- ternary

(b) Which of the following is not a logical operator?

- ++
- &&
- ||
- !

(c) Which of the following constructs is equivalent to the ternary operator in Java language?

- if
- if-else
- nested if
- switch-case

(d) Which of the following is a relational operator?

- &
- $
- !=
- !

**Answer**

(a) unary

(b) ++

(c) if-else

(d) !=

Functions are the built-in modules that can be used in our program to perform a specific operation. There are some mathematical functions that are used for specific functions. For example, we can use `Math.sqrt( )`

function to return square root of a positive number, `Math.random( )`

and `Math.ceil( )`

to return random number in a range of numbers to return the next higher integer number.

Based on the above discussion, answer the following questions:

(a) What will be displayed, if the following statement is executed?`System.out.println(Math.sqrt(-25));`

- Infinite
- -5.2
- NaN
- Logical error

(b) Math.random( ) function returns a random number in the range:

- between 0 and 1
- between -1 to 0
- between -1 to 1
- None of the above

(c) Which of the following function will return the next higher integer number?

- Math.max( )
- Math.min( )
- Math.floor( )
- Math.ceil( )

(d) Which of the following statement is true for Math.max( )?

- It will always result in
`int`

type value. - It will always result in
`double`

type value. - The resultant data type will depend upon the type of arguments.
- It will return
`float`

type, if arguments are`double`

type.

**Answer**

(a) NaN

(b) between 0 and 1

(c) Math.ceil( )

(d) The resultant data type will depend upon the type of arguments.

Java, like all other programming languages uses some statements that allow us to check a condition and execute certain parts of a code depending on whether the condition is true or false. Such statements are called conditional statements. We can also use a conditional statement within another conditional statement. The inner conditional statement is executed only when the outer condition is true. The conditional statement can also be a multiple branching statement.

Based on the above discussion, answer the following questions:

(a) Which of the following is not a decision making statement?

- if - else
- if
- break
- if-else-if

(b) A conditional statement used within another conditional statement is known as ...............

- nested conditional statement
- embedded conditional statement
- accumulated conditional statement
- None of the above

(c) Which of the following is called as multiple branching statement?

- if and only if
- switch
- control
- shift

(d) Which of the following is not a component of multiple branching statement?

- break
- default
- case
- pause

**Answer**

(a) break

(b) nested conditional statement

(c) switch

(d) pause

The following program segment calculates the norm of a number. The norm of a number is the square root of sum of squares of all the digits of the number.

Sample Input: 68

Sample Output: The norm of 68 is 10

[Hint: 6x6 + 8x8 = 36 + 64 = 100

The square root of 100 is 10. Hence, norm of 68 is 10]

There are some places in the program left blank marked with ?1?, ?2?, ?3? and ?4? to be filled with variable/function/expression.

```
Scanner in = new Scanner(System.in);
int num;
int d, s = 0;
num = ......?1?......
while (......?2?......)
{
d = num % 10;
s = ......?3?......
num = num / 10;
}
System.out.println("The norm of " + num + " is " + ......?4?......);
```

Based on the above discussion, answer the following questions:

(a) Which of the following will be filled in place of ?1?

- in.nextInteger;
- in.NextInt( );
- in.nextInt( );
- in.nextint( );

(b) What will you fill in place of ?2?

- num > 0
- num < 0
- num > 1
- num = 0

(c) What will you fill in place of ?3?

- s + d * d
- s * d + d
- s * s + d
- s + d

(d) What will you fill in place of ?4?

- Math.sqrt(s)
- Math.SQRT(s)
- Math.sqrt(n)
- Math.sqrt(num)

**Answer**

(a) in.nextInt( );

(b) num > 0

(c) s + d * d

(d) Math.sqrt(s)

The completed program is given below for reference:

```
Scanner in = new Scanner(System.in);
int num;
int d, s = 0;
num = in.nextInt( );
while (num > 0)
{
d = num % 10;
s = s + d * d;
num = num / 10;
}
System.out.println("The norm of " + num + " is " + Math.sqrt(s));
```