TOTAL QS = 45Time [ 00 : 00 : 00 ]
00:00:00

Java Basics: Loops WHILE, FOR, DO WHILE with Break and Continue Online Test 1

Instructions

Total Questions: 45

Total Minutes: 45

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on Java Loops like WHILE Loop, FOR Loop, DO WHILE Loop and Enhanced FOR Loop. Break and Continue are also tested. This test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics.

Go through the above Java notes on these topics before attempting this test.

All the Best

Challenge SCORE

0 / 45

Take This Exam
1) What is a Loop in Java programming language?
2) Choose a valid loop name in Java below.
3) Every loop in Java has a condition that should be ___ in order to proceed for execution. (TRUE / FALSE)
4) Choose the correct syntax of the WHILE loop in Java below.
5) Choose the correct Syntax of FOR loop in Java below.
6) Choose the correct syntax of the DO WHILE loop in Java below.
7) Choose the correct syntax of an Enhanced FOR loop in Java below.
8) State TRUE or FALSE. A WHILE loop in Java executes the statements at least once even the condition is not satisfied.
9) A BREAK statement inside a Loop like WHILE, FOR, DO WHILE and Enhanced-FOR causes the program execution ___ Loop.
10) A CONTINUE statement inside a Loop like WHILE, FOR, DO-WHILE and Enhanced-FOR causes the program execution ___ the loop.
11) Choose the Java-Code below with a never-ending loop.
12) A loop in Java generally contains a Loop-Counter variable. State TRUE or FALSE.
13) An Increment operator "++" and/or a Decrement operator "--" are used along with a Loop-Counter variable in Java. (TRUE / FALSE).
14) What is the output of the below Java program?
int a=1;
while(a<4)
{
  System.out.print(a + " ");
  a++;
}
15) What is the output of the below Java program with a decrement operator and WHILE-loop?
int a=4;
while(a>0)
{
 System.out.print(a + " ");
 a--;
}
16) What is the output of the below Java program?
String str="FOX";
int i=0;
while(i<str.length())
{
  System.out.print(str.charAt(i));
  i++;
}
17) What is the output of the below Java program with WHILE, BREAK and CONTINUE?
int cnt=0;
while(true)
{
  if(cnt > 4)
    break;
  if(cnt==0)
  {	
    cnt++;
    continue;
  }
  System.out.print(cnt + ",");
  cnt++;
}
18) What is the main difference between a WHILE and a DO-WHILE loop in Java?
19) What is the value of "age" in the below Java program with a DO-WHILE loop?
int age=20;
do
{
  age++;
}while(age<20);
System.out.println(age);
20) What is the output of the below java program that implements nesting of loops?
int i=1, j=1;
while(i<3)
{
  do
  {
    System.out.print(j + ",");
    j++;
  }while(j<4);
  i++;
}
21) What is the output of the below Java program?
int time=50;
do
{
System.out.print(time + ",");
time++;
}while(time < 53)
22) What is the output of the below Java program?
char ch[] = {'A', 'B', 'C'};
int i=0;
do
{
  System.out.print(ch[i] + ",");
  i++;
}while(i < ch.length);
23) What is the output of the below Java program?
String str[] = {"A","B","C"};
int i=0;
do
{
  if(i>= str.length)
    break;
  System.out.print(str[i] + ",");
  i++;
}while(true);
24) What is the output of the below Java code with a FOR loop?
for(int i=1; i<5; i++)
{
  System.out.print(i +",");
}
25) What is the output of the below Java code?
boolean[] ary = {true, false, true, true};
for(int i=0; i<ary.length; i++)
{
    System.out.print(ary[i] +",");
}
26) What is the output of the below Java code?
int score=1;
for(; true; score++)
{
  System.out.print(score +",");
  if(score > 3)
    break;
}
27) What is the output of the below Java program with FOR loop?
for(int j=0; j<5;j++;)
  System.out.print(j + ",");
28) State TRUE or FALSE. In a FOR loop, the Initialization-part, Condition-part and Increment/Decrement part can be empty.
29) Any loop can be nested inside any loop in Java. (TRUE/FALSE).
30) A Loop in Java language may contain ___.
31) In Java language, BREAK or CONTINUE statements can be implemented inside a Loop only with the help of ___ statements to avoid never-ending loops.
32) The Enhanced FOR loop in Java was introduced by ___.
33) An enhanced FOR loop work with only Collection type data. Examples of Collection are ___.
34) What is the output of Java Enhanced FOR loop below?
String names[] = {"MOGLI", "SHAREKHAN", "BALU"};
for(String str: names)
{
  System.out.print(str + ",");
}
35) An Enhanced FOR loop in Java misses ___ and __ compared to the old-style FOR loop.
36) What is the output of the Java program with Enhanced FOR loop below?
String countries[] = {"BRAZIL", "CHILE", "SYDNEY"};
int i=0;
for(String str: countries)
{
  if(i<2)
    ;
  else
    break;
  System.out.print(str + ",");
  i++;
}
37) What is the output of the Java code snippet?
int i=0;
for(i=1; i<=6;i++)
{
  if(i%3==0)
    continue;
  System.out.print(i+",");
}
38) A BREAK or CONTINUE statement applies only to the ___ loop.
39) A BREAK-WITH-LABEL or CONTINUE-WITH-LABEL are used in particular in Java to select __ loop either to Break or Continue.
40) Choose rules for naming a Label in Java below.
41) State TRUE or FALSE. You can exit an inner loop without using a BREAK statement but with a CONTINUE and Label on the outer loop.
42) The keyword "goto" can be used in Java programs with labels. (TRUE/FALSE)
43) Is it possible to break all loops with a single BREAK with a Label statement? (YES/NO)
44) What is the output of the Java code snippet below?
outer:
for(int i=1; i<=4;i++)
{
  inner:
  for(int j=1; j<=4;j++)
  {
    if(j==1)
      break outer;
  }
System.out.print("A");
}
45) What is the output of the below Java program?
outer:
for(int i=1; i<=2;i++)
{
  inner:
  for(int j=1; j<=2;j++)
  {
    if(j>i)
      break inner;
    System.out.print(j +",");	
  }
}

 

 

ExamTray App is now Available on Google Play EXAMTRAY android app link