Saturday, May 16, 2009

Java Basic questions:Control Statements

Following are some good basic questions of Control statements read them and make your fundamentals strong

1) What are the programming constructs?
Ans: a) Sequential
b) Selection -- if and switch statements
c) Iteration -- for loop, while loop and do-while loop

2) class conditional {
public static void main(String args[]) {
int i = 20;
int j = 55;
int z = 0;
z = i < j ? i : j; // ternary operator
System.out.println("The value assigned is " + z);
}
}
What is output of the above program?
Ans: The value assigned is 20

3) The switch statement does not require a break.
a)True
b)False
Ans: b.

4) The conditional operator is otherwise known as the ternary operator.
a)True
b)False
Ans: a.

5) The while loop repeats a set of code while the condition is false.
a)True
b)False
Ans: b.

6) The do-while loop repeats a set of code atleast once before the condition is tested.
a)True
b)False
Ans: a.

7) What are difference between break and continue?
Ans: The break keyword halts the execution of the current loop and forces control out of the loop.
The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.

8) The for loop repeats a set of statements a certain number of times until a condition is matched.
a)True
b)False
Ans: a.

9) Can a for statement loop indefintely?
Ans : Yes.

10) What is the difference between while statement and a do statement/
Ans : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

Links:-
Home
India Online
Other Java Questions
Open Your Online Store for free!!!

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP