
Input in java
QuizĀ by Ceena Joseph
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
Find the type of error in the following code to find the addition of two numbers:
public class Example{
public static void main(String args []) {
Ā Ā Ā int a = 40;
Ā Ā Ā int b = 60;
Ā Ā Ā System.out.println(a+b);
} }
Find the type of error in the following code to find the multiplication of two numbers:
public class Example{
public static void main(String args []) {
Ā Ā Ā int a = 40;
Ā Ā Ā int b = 60;
Ā Ā Ā int c = a*b;
Ā Ā Ā System.out.println(c*a*b);
} }
Find the type of error in the following code to divide two numbers:
public class Example{
public static void main(String args []) {
Ā Ā Ā int a = 40;
Ā Ā Ā int b = 0;
Ā Ā Ā System.out.println(a/b);
} }
Which Scanner class method is used to read string value from the user?
Which method does not store string value after space?
Which Scanner class method is used to read integer value from the user?
What is the output of the following code if the user inputs '5' followed by '10'?
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt(); System.out.println(a + b);
What will the following code snippet output if the user enters 5.6 when using Scanner:
Scanner scanner = new Scanner(System.in);
double value = scanner.nextDouble();
System.out.println(value);
What will be the output of the following code snippet if the user inputs 'Hello' when running
Scanner scanner = new Scanner(System.in);
String text = scanner.next();
System.out.println(text);
What will be displayed by the following code?
Scanner scanner = new Scanner(System.in);
char letter = scanner.next().charAt(2);
System.out.println(letter);
If the user inputs 'Computer', what will be printed?
What will be displayed by the following code?
Scanner scanner = new Scanner(System.in);
char letter = scanner.next().charAt(4);
System.out.println(letter);
If the user inputs 'Hello', what will be printed?