Exercise 01: Simple conditional statement

Easy Exercises   For Beginners  Required knowledge 
 01   02   03   04   By title 

I started this serie Java exercises, because some members wrote to me that the easy quizzes, puzzles and assignments are not easy for them. Therefore, I realized that this serie might help the beginners even better. In this serie I keep the code as simple as I can and hope that you guys can enjoy it.

Read More: Java Conditional Statements

Java exercise 01: A simple conditional statement

Level: Very easy
What happens if the following code is compiled and run?

public class MyClass
  public static void main(String[] args)
    int x = 3;
    if(x < 3)
Author: Sar Maroof

Select the correct answer.

Answer explanation

  1. The first statement if(x > 3) returns false, because the value of x is not greater than 3.
  2. The body of the else statement is executed, because the if statement returns false. The statement System.out.print(“y”); writes y to the standard output.

The correct answer is: b.

If you found this difficult, you might consider reading my book Java quizmaster for beginners. It is easy to understand, organized to learn Java in 17 days and it guides you to master Java code by solving 105 quizzes and 117 assignments. This book explains each chapter properly before starting with exercises and assignments. It is available on Amazon. See inside the book here!

Please, leave your questions, feedback and suggestions in the comments below!
SarMaroof.com offers a practical method to learn and improve your Java skills. It avoids unnecessary long boring theoretical explanations, but it uses many exercises and quizzes.

Sar Maroof is graduated from HBO Amsterdam "higher professional education". He is a professional computer programming teacher, gives master classes and publishes technical articles. His experience with developing software started from 2001 and he has worked as a software developer for several big as well as small companies and later as a freelancer. He is the author of Java quizmaster and Build a Java application in 7 days.

Books by Sar Maroof


 Subscribe to Sar Maroof's RSS feeds!
 Mail this page to a friend!
 Bookmark this page!

Leave a Reply

Your email address will not be published. Required fields are marked *