What is the output of following program ?

Code
  1.  

  2. class Test {

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

  4. {

  5.  for(int i=0;i<2;i++) {  

  6. System.out.println(i);  

  7. }

  8. }

  9. }
Copyright GeekInterview.com



(a) Goes into infinite loop

(b) 0,1

(c) 0,1,2

(d) None

Showing Answers 1 - 13 of 13 Answers

Ramesh

  • Mar 14th, 2005
 

please verify the question and answer. the correct is (b) it prints 0,1. Pl justify the above answer. is any thing wrong in the question otherwise.

  Was this answer useful?  Yes

sunil

  • Apr 6th, 2005
 

Answer B 
0,1

  Was this answer useful?  Yes

wtf

  • May 2nd, 2005
 

Why is this going into an infinite loop? :s 
the answer must be (B)

  Was this answer useful?  Yes

Prakash.M

  • Dec 1st, 2005
 

The answer is B as it excecutes for two times and it results in 0,1

  Was this answer useful?  Yes

Riaz

  • Dec 12th, 2005
 

First think before speak.Answer must be (B) 

  Was this answer useful?  Yes

prasanta

  • Jan 6th, 2006
 

yes,answer is b

it print 0,1

  Was this answer useful?  Yes

dile_sahoo

  • Mar 4th, 2007
 

Its answer if B(0,1),and i want tell you that first u test then put that type of silly question.This is the basic issue of a loop,Donot mind

  Was this answer useful?  Yes

Subhash

  • Jul 15th, 2011
 

Question Could be like this

Code
  1. class Test {

  2. public static void main(String args[]) {

  3. for(int i=0;i<2;i++) {

  4. System.out.println(i--);

  5. }

  6. }

  7. }

  8.  

Ans: It goes to infinite loop

  Was this answer useful?  Yes

coddd

  • Jan 17th, 2013
 

The answer will be 0,1

If the the question is like "System.out.println(i--);
then it will print infinite loop of 0;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions