Page 97 - CA_Blue( J )_Class10
P. 97
2. Alice starts her project by creating a new Java class. She writes a simple main method to print "Welcome, India!" but encounters
an error.
class prog {
public static void main(String[] args)
{
System.out.println("Welcome, India")
}
}
What type of error is Alice encountering, and how can she fix it?
a. Logical error; She needs to change the string to "Welcome, India!!!".
b. Syntax error; She needs to add a semicolon at the end of the System.out.println statement.
c. Runtime error; She needs to run the program again.
d. Compilation error; She needs to change the method signature.
Ans. 1. Yes he will able to take execute the line and the output will be 4.0.
2. b
Unsolved Questions
A. Tick ( ) the correct answer.
1. Which of the following types of error will give the following code?
for(int i=1;i>10;i++)
a. Syntax b. Runtime
c. Logical d. None of these
2. The scanner sc= new Scanner(System.in) code will give a\an ………………… error.
a. Syntax b. Runtime
c. Logical d. None of these
3. ………………… are non-executable statements used to explain the code.
a. Comments b. Errors
c. Logical d. Keywords
4. Which of the following is not used to write a comment?
a. /** b. //
c. / d. /*
5. Which of the following is used to input a float value using Scanner class?
a. next() b. nextInt()
c. nextDouble() d. nextFloat()
6. Which of the following is the correct way to initialize an integer variable x with the value 10 in Java?
a. int x = 10; b. int x := 10;
c. let x = 10; d. x = 10;
7. Which of the following methods in Java is used to receive command-line arguments?
a. public static void start(int[] args) b. public static void start(String args)
c. public static void main(int args) d. public static void main(String[] args)
8. Which package do you need to import to use the Scanner class in Java?
a. java.io b. java.util
c. java.lang d. java.net
9. What is the output of the following code if the user inputs "25 4.5 Hello"?
Scanner sc = new Scanner(System.in);
int a = sc .nextInt();
double b = sc .nextDouble();
String c = sc .next();
95
Input in Java 95

