GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 472 of 502    Print  
Output of Java Program
What is the output of the following program?

class A
{
public static void main(String[] s)
{
System.out.println(s[1] + s[2] + s[3]);
}
}

java A 12345

Options
(i) 1
(ii) 12
(iii)1234
(iv)234
(v) Compilation Error





  
Total Answers and Comments: 22 Last Update: November 02, 2009     Asked by: khadarzone 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: khadarzone
 
I think the output will be (iv)234

since s[0] = 1, s[1] = 2, s[3]=3, s[4]=4, s[5] = 5,
we are printing s[1] + s[2] + s[3] , which means 234.

Please correct me if i am wrong

Above answer was rated as good by the following members:
getravi2k, julian_1982, er.mukesh_208, sreekesh_anand, shouvanik1979, Nishchal1982Jain, bino75, sandeep549, sujithkthomas
  Sorting Options  
  Page 1 of 3   « First    1    2    3    >     Last »  
April 14, 2008 07:28:57   #1  
abuthahir.d Member Since: January 2008   Contribution: 9    

RE: Output of Java Program
array Index out of bound exception
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
April 14, 2008 07:29:33   #2  
abuthahir.d Member Since: January 2008   Contribution: 9    

RE: Output of Java Program
ArrayIndexOutOfBoundException will occure since the length of array s will be 0
 
Is this answer useful? Yes | No
April 14, 2008 10:32:43   #3  
khadarzone Member Since: September 2007   Contribution: 17    

RE: Output of Java Program
I think the output will be (iv)234

since s[0] 1 s[1] 2 s[3] 3 s[4] 4 s[5] 5
we are printing s[1] + s[2] + s[3] which means 234.

Please correct me if i am wrong

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
April 14, 2008 10:41:44   #4  
abuthahir.d Member Since: January 2008   Contribution: 9    

RE: Output of Java Program
Khadar i tried this code . it gives that exception

for the foll reason :
when u give a CLA(command line argument) it will be inserted in the index 0 of the array and then will proceed to 1 2 ....

so as per the question "12345" will be at s[0] . and length of that aray will be 1when u try to access s[1] we are trying for 2nd element which is unavailable.....


Hope this answers u :-)

 
Is this answer useful? Yes | NoAnswer is useful 7   Answer is not useful 0Overall Rating: +7    
June 09, 2008 11:50:23   #5  
vegetto Member Since: June 2008   Contribution: 10    

RE: Output of Java Program
hi there
the answer for this question of yours will be option (d) because you have not entered any input after 12345 which is only stored in s[0] corresponding to it's string equivalent but as far as s[2] and s[3] are concerned then you have not submitted any input so it will lead to runtime error. supply with inputs after giving space after every input 3 times and hit enter and you will get the result.byeeee

 
Is this answer useful? Yes | No
June 15, 2008 00:28:37   #6  
interviewprep9 Member Since: June 2008   Contribution: 10    

RE: Output of Java Program
Output is v --> Compilation Error. Exception: ArrayIndexOutOfBounds

If we give as java A 1 2 3 4 5 then the output is 234

Thx.

 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
June 30, 2008 05:02:55   #7  
gvkirankumar05 Member Since: June 2008   Contribution: 1    

RE: Output of Java Program
getting ArrayIndexOutOfBoundException bcz here pass only one argument. that will be stored into s[0]. there is no values on remaining index position.
 
Is this answer useful? Yes | No
September 22, 2008 06:59:49   #8  
atulkalaskar Member Since: September 2008   Contribution: 1    

RE: Output of Java Program
v. Compailation Error.

array index out of bound exception.

 
Is this answer useful? Yes | No
September 22, 2008 23:49:11   #9  
Tarun Wadhwa Member Since: August 2008   Contribution: 10    

RE: Output of Java Program

The output of the program will be 234


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
September 22, 2008 23:50:00   #10  
Tarun Wadhwa Member Since: August 2008   Contribution: 10    

RE: Output of Java Program
The output of the program will Be 234
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
  Page 1 of 3   « First    1    2    3    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape