Page 140 - CA_Blue( J )_Class9
P. 140
v = 1 / ((1 / u) + (1 / f));
System.out.print("Enter focal length of the lens: ");
f = sc.nextDouble();
v=(u*f)/(f+u);
System.out.println("Distance of the image from the lens: " + v);
}
}
3. Which class uses delimiters to break the inputs into tokens?
Ans. The Scanner uses delimiters to break the inputs into tokens.
4. Define “try” and “catch”.
Ans. “try” is the portion where we write those statements that may have some error.
“catch” is used to handle the exception that has been generated in the try block. In the catch block, we can write our
own error message or handle the error to suit our needs rather than showing the system-generated message.
5. What is an exception?
Ans. During execution of a program, occurring of any error stops the execution. This situation is known as an exception.
6. Differentiate between Syntax and Logical errors.
Ans. A syntax error occurs when there is a grammatical mistake in the code, such as a missing semicolon or incorrect use of keywords.
A logical error occurs when there is a flaw in the logic of the program, leading to incorrect output despite the code
running without crashing.
7. What is the difference between the Scanner class functions nextInt() and nextDouble()?
Ans. nextInt() nextDouble()
Used to input an integer value. Used to input a real value.
Example: int n = sc.nextInt(); Example: double d = sc.nextDouble();
8. Name the package used for Scanner class.
Ans. java.util package is used for Scanner class.
9. What is the use of the keyword import in Java Programming?
Ans. The import keyword enables us to use classes from a given package in your program.
10. Name the type of error (syntax, runtime or logical error) in each case given below:
(i) Division by a variable that contains a value of zero.
(ii) Multiplication operator used when the operation should be division.
(iii) Missing semicolon.
Ans. (i) Runtime Error (ii) Logical Error
(iii) Syntax Error
Unsolved Questions
A. Tick ( ) the correct answer.
1. int a=30 contains which type of error?
a. Syntax b. Runtime
c. Logical d. Output
2. Scanner sc= new Scanner(System.in) is a ………………… error.
a. Syntax b. Runtime
c. Logical d. Type
3. int a=5.6; is a ………………… error.
a. Syntax b. Runtime
c. Logical d. Type
138 Touchpad Computer Applications-IX

