Java conditions

👁 15
statistics
by Dr. Osama M. Khaled last modified 2022-07-19T05:23:42+01:00

The quiz presents a Java code that takes an input and prints an output based on some conditions. Take the quiz and test your understanding about conditional statements

Questions #: 5
Time:
Pass Score: 80.0%
Style
Mode
1     import java.util.Scanner;
2 public class Exe_Java_Condition {
3  public static void main(String[] args){
4    Scanner in = new Scanner(System.in);
5    System.out.print("Input number: ");
6    int input = in.nextInt();
7    if (input > 0){
8     System.out.println("Positive Number");
9   } else if (input < 0){
10     System.out.println("Negative Number");
11    } else{
12     System.out.println("Zero");
13    }
14 }
15 }

What is the expected result if input is 35?

** lower case answer will be considered correct in this exercise

Missing
POINTS (1)

Correct Answer

Explanation


What is the result if input is -35?

** lower case answer will be considered correct in this exercise

Missing
POINTS (1)

Correct Answer

Explanation


What is the result if input is 0?

** lower case answer will be considered correct in this exercise

Missing
POINTS (1)

Correct Answer

Explanation


What is the input for the code to print "Positive Number"?

POINTS (1)

Correct Answer

Explanation


What is the difference between the following code from the original one in terms of performance?

Changing the IF code slightly, but providing the same functionality
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input number: ");
int input = in.nextInt();
if (input > 0){
System.out.println("Positive Number");
}
if (input < 0){
System.out.println("Negative Number");
}
if (input == 0) {
System.out.println("Zero");
}
}
}
POINTS (1)

Correct Answer

Explanation


Views:
Trials:
Avg score: