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 will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

11 comments for Programming Interview Questions on loops

  1. the ans and qns are very good for experienced people.

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

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

      Delete
    3. 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
  3. Nice post to understand pre-implementation and post-implementation

    ReplyDelete

Select Menu