Beginner Quizzes – Java Control Statements

The following Java exercise(s) are designed for beginner level programmers. If the level is too hard, then I recommend reading my article about this topic, which offers a theoretical explanation including more exercises. Read More: Java Conditional Statements Read More: Java Iteration (Loop) Statements

Article: Java Conditional Statements
Quizzes: Beginner  Intermediate  Advanced 

conditional-statements-color

Quiz 1:  Easy “for” loop statement for beginners

What appears in the standard output when this program is invoked?

public class ForLoop {

	int y = 3;

	void methodA(){
		int y = 2;
		for(int x = 0; x < 3; x ++ ) {
			System.out.print(" y" + y);
			y -- ;
		}
	}
	public static void main(String[] args){
		ForLoop lc = new ForLoop();
		lc.methodA();
	}
}

Select the correct answer.



Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Quiz 2: One simple loop

What happens when the following program is compiled and run?

public class Loop {

	public static void main(String[] args){
		for(int x = 0; x < 3; x ++ ) {
			System.out.print(" x" + x);
		}
	}
}

Select the correct answer.



Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Quiz 3: Easy while loop

What happens when the following program is compiled and run?

public class MyLoop {

	void methodA(){
		int x = 0;
		while(x < 3) {
			x ++ ;
			System.out.print("-x" + x);
		}
	}
	public static void main(String[] args){
		MyLoop myLoop = new MyLoop();
		myLoop.methodA();
	}
}

Select the correct answer.



Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Quiz 4:  Easy If else statement

What happens when the following program is compiled and run?

public class Statement {

	public void methodA(){
		int a = 3;
		int b = 2;
		if(a < b) System.out.print("a");
		else System.out.print("b");
	}
	public static void main(String[] args){
		Statement st = new Statement();
		st.methodA();
	}
}

Select the correct answer.



Please, leave your questions, feedback and suggestions in the comments below! If you need more explanation by any of the answers, just let me know to update it for you!

Quiz 5: Easy switch block of char

What happens when the following program is compiled and run?

public class Switch {

	public void switchTester(){
		char myCahr = 'a';
		switch(myCahr) {
			case 'a':
				System.out.print("a");
			default:
				System.out.print("b");
		}
	}
	public static void main(String[] args){
		Switch st = new Switch();
		st.switchTester();
	}
}

Select the correct answer.


Megisoft.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. The author of Megisoft is Sar Maroof who has more than a decade of experience with web development mainly with Java, MySql, HTML and more..
Article: Java Conditional Statements
Quizzes: Beginner  Intermediate  Advanced 

Suggested Articles:


Sar Maroof's New Book "Java Quizmaster For Beginners"
Author: Sar Maroof
Many years of experience with developing web applications mainly with Java.
Sun Certified JSP as well as EJB
CIW Certified Internet Webmaster
Applied Science in Physics HBO Amsterdam
Bachellor Science in Physics at Basra university.
 Subscribe To sarmaroof RSS Feeds! (Your Browser)
 Mail This Page To A Friend!
 Bookmark This Page!
Share on FacebookTweet about this on TwitterShare on RedditShare on LinkedIn

1 Comment

Add a Comment
  1. This is my favorite Java blog, because it explains Java topics easy with different exercises!

Leave a Reply

megisoft © 2016