Control Statement Problems(JAVA)

Updated: Oct 17, 2020

Here I have given you the practice questions which are based on the control statements. Control statements are for loop, while loop, do-while loop, for-each loop, and other things which help you to control the program execution.


1.Write programs using for loop, while loop, for-each loop, do-while loop to find 3rd minimum integer values from a given set of integers.

Integer values - 4,54,25,8,436,4,43,598.




2. What will be the output of the following:-


class selection_statements {

public static void main(String args[]) {

int var1 = 5;

int var2 = 6; if ((var2 = 1) == var1)

System.out.print(var2);

else

System.out.print(++var2);

}

}





3.Output Of the following program:-

  1. class comma_operator

  2. {

  3. public static void main(String args[])

  4. {

  5. int sum = 0;

  6. for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)

  7. sum += i;

  8. System.out.println(sum);

  9. }

  10. }




4.Output Of the following program:-

  1. class jump_statments

  2. {

  3. public static void main(String args[])

  4. {

  5. int x = 2;

  6. int y = 0;

  7. for ( ; y < 10; ++y)

  8. {

  9. if (y % x == 0)

  10. continue;

  11. else if (y == 8)

  12. break;

  13. else

  14. System.out.print(y + " ");

  15. }

  16. }

  17. }




5.Output of the following program:-

  1. class Output

  2. {

  3. public static void main(String args[])

  4. {

  5. final int a=10,b=20;

  6. while(a<b)

  7. {

  8. System.out.println("Hello");

  9. }

  10. System.out.println("World");

  11. }

  12. }



6. Output of the following:-

  1. class Output

  2. {

  3. public static void main(String args[])

  4. {

  5. int a = 5;

  6. int b = 10;

  7. first:

  8. {

  9. second:

  10. {

  11. third:

  12. {

  13. if (a == b >> 1)

  14. break second;

  15. }

  16. System.out.println(a);

  17. }

  18. System.out.println(b);

  19. }

  20. }

  21. }


7. Pattern printing problems:-


a. Pyaramind problem

  *
   * * 
   * * * 
   * * * * 
  * * * * *



b. Right Triangle

*
* *
* * *
* * * *
* * * * *


c. Left Triangle:-

           * 
         * * 
       * * * 
     * * * * 
   * * * * * 


d. Diamond Shape:-

 *
 ***
 *****
 *******
 *********
 *******
 *****
  ***
  *


e. Downward triangle:-

* * * * * 
* * * * 
* * * 
* * 
* 


f.Mirrored right triangle:-

     *
    **
   ***
  ****
 *****
******


g. Reverse Pyramid

* * * * * 
* * * * 
* * * 
* * 
* 


h. Right down triangle:-

*****
 ****
  ***
   **
    *


i. Right pascal triangle:-

* 
  * * 
    * * * 
      * * * * 
        * * * * * 
      * * * * 
    * * * 
 * * 
*  


j. Left pascal triangle:-

    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *


k. Sandglass star pattern:-

* * * * * 
 * * * * 
  * * * 
   * * 
    * 
    * 
   * * 
  * * * 
 * * * * 
* * * * * 



l. Alphabet A pattern:-

*** 
* *
***
* *
* *
* *
 


m. Traiangle star pattern:-

    *
   * *
  *   *
 *     *
*********

n. Down Triangle:-

*********
 *     *
  *   *
   * *
    *

o. Diamond shape:-

    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *


Numbers Patterns:-

1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

             1
           1   1
         1   2   1
       1   3   3   1
     1   4   6   4   1

   1
  212
 32123
4321234
 32123
  212
   1

1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

10101
01010
10101
01010
10101

1
10
101
1010
10101

1 2 3 4 5 
 2 3 4 5 
  3 4 5 
   4 5 
    5 
   4 5 
  3 4 5 
 2 3 4 5 
1 2 3 4 5



Alphabet Patterns:-

A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F

A 
B B 
C C C 
D D D D 
E E E E E 
F F F F F F 

A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F

     A 
    A B 
   A B C 
  A B C D 
 A B C D E 
A B C D E F

     A
    B B
   C   C
  D     D
 E       E
F         F
 E       E
  D     D
   C   C
    B B
     A

A B C D E F E D C B A
A B C D E   E D C B A
A B C D       D C B A
A B C           C B A
A B               B A
A                   A


If you like or dislike this post, please leave a comment so in the future we will become better and help you.


Also, share it with your friends...


©2020 by Disturbed Rover

  • Facebook
  • Instagram