Think Output:

Program #1:

  1. package com.instanceofjavaforus;
  2.  
  3. public class Loops {
  4.  
  5. public static void main(String args[]){
  6.  
  7.             int i=0;
  8.  
  9.             for( i=0;i<5;i++){               
  10.                 System.out.println(i);
  11.              }
  12.  
  13.              System.out.println("value of i after completion of loop: "+i);
  14. }
  15. }





Program #2:

 

  1. package com.instanceofjavaforus;
  2.  
  3. public class LoopsDemo2 {
  4.  
  5. public static void main(String args[]){
  6.  
  7.           int a=0,b=0;
  8.  
  9.             for(int i=0;i<5;i++){
  10.                 if(++a>2||++b>2){
  11.                    a++;
  12.                   }
  13.           }
  14.  
  15.           System.out.println("a= "+a+" b="+b);
  16.         
  17. }
  18. }









Program #3:

  1. package com.instanceofjavaforus;
  2.  
  3. public class LoopsDemo3 {
  4.  
  5. public static void main(String args[]){        
  6. int i=5;
  7. System.out.println(i++);
  8. System.out.println(i--);
  9. }
  10. }




Instance Of Java

We are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Type Casting in java?
»
Previous
Convert Byte Array to String

11 comments for Programming Interview Questions on loops

  1. blogger_logo_round_35

    the ans and qns are very good for experienced people.

    ReplyDelete
  2. blank
  3. blogger_logo_round_35
  4. blogger_logo_round_35
    Replies
    1. blogger_logo_round_35

      kindly post the explanation of Programs# 2 ?? Not getting.

      Delete
    2. blogger_logo_round_35

      kindly give the explanation of programs# 2 not getting the output

      Delete
    3. blogger_logo_round_35

      class J
      {
      public static void main(String args[])

      {

      int a=0,b=0;

      for(int i=0;i<5;i++)
      {
      if(++a>2||++b>2)
      {
      a++;
      System.out.println("i:"+i);
      System.out.println("a:"+a);
      System.out.println("b:"+b);
      }
      }

      System.out.println("a= "+a+" b="+b);
      }
      }



      try this ..
      you will get it .

      Delete
  5. blogger_logo_round_35

    Nice post to understand pre-implementation and post-implementation

    ReplyDelete
  6. blogger_logo_round_35

Select Menu