|
|
Author | Message |
---|
jOhNy Active member
| Subject: OUTPUT CONFUSION!! Sat Jan 31, 2009 3:28 pm | |
| hullo frndz... i hav a very intriguin ques which came in my prelims(they always come in our skul only!!) Give the output: int[]arr={2,4,6,8,10}; int x=1; arr[x++]=++arr[x++]+arr[x++]: for(int i=0;i<5;++i) { System.out.println(arr[i]); } my output-2 15 6 8 10 i think it's rite..everyone says itz wrong so plzz help.. thnxx a lot. |
|
| |
jOhNy Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 06, 2009 8:35 pm | |
| someone plzz help!! |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Sun Feb 08, 2009 11:49 am | |
| no......jony de answer is 2 15 7 8 10 |
|
| |
jOhNy Active member
| Subject: Re: OUTPUT CONFUSION!! Sun Feb 08, 2009 5:04 pm | |
| how come siya?? |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Mon Feb 09, 2009 12:37 am | |
| see d diff. in ur answer n mine is only of 6 n 7 no.so i will tell u d reason.in 3rd line of d question,by ++arr[x++],d value of arr[2] is changed frm 6 to 7 bcoz of a prefix increment of d value of arr[2] on d whole. |
|
| |
monika
| Subject: Re: OUTPUT CONFUSION!! Mon Feb 09, 2009 3:48 pm | |
| ya siya's right |
|
| |
akshay Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 13, 2009 8:42 am | |
| hey guys the ans is : 15 7 8 10 1. output starts from 15 cause of ++i ( 'i' gets incremented before any sort of evaluation or execution) 2. the outputs dont not come in a row cause you've used the println statement which prints each output in a diff line |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 13, 2009 1:01 pm | |
| hey as_24!!!!!!check it on comp. d output is not ur answer yaar.i have checked it many times.u 2 check it!!!!!!!!! |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Sat Feb 14, 2009 1:30 pm | |
| hey!!!!! ne1.plz....check it n confirm |
|
| |
akshay Active member
| Subject: Re: OUTPUT CONFUSION!! Sun Feb 15, 2009 2:38 am | |
| sorry, my mistake=P |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Sun Feb 15, 2009 9:44 am | |
| arre no,doesnt matter yaar.....its gud u checked it n now all doubts cleared... |
|
| |
jOhNy Active member
| Subject: Re: OUTPUT CONFUSION!! Wed Feb 18, 2009 8:55 pm | |
| nooo siya..all doubts r not cleared..i cheked it on the comp..im getting 2 15 7 9 10 wotsay? |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Thu Feb 19, 2009 12:12 am | |
| arre johny check it again.i have checked it 100 times n each time m gettin dis 2 15 7 8 10 n btw i have got d logic for my answer but cudnt get ne for urs.so plz. check it n confirm it.... |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:17 pm | |
| hey!plz. ne body check dis n tell me d final answer!!i think johny sir has forgotten abt his prob. only |
|
| |
jOhNy Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:20 pm | |
| nono siya maam..i haven't 4gotten it...my bluej isn't working so i can't confirm it... |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:22 pm | |
| okk.. but m 100000000% dat my answer is correct.well nebody plllllz...confirm it...n johny u got a blueJ for ur comp. also in a pirated CD!!!!!!!!!!!!!!!!he he |
|
| |
jOhNy Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:29 pm | |
| arre babaa..pirated cdz ka bhoot sawar ho gya kya??mera toh bheja bhi pirated hai..hehee |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:55 pm | |
| hey... i copy pasted this program...it is not working in my blueJ!!!! |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:10 pm | |
| int[]arr={2,4,6,8,10}; int x=1; arr[x++]=++arr[x++]+arr[x++]: for(int i=0;i<5;++i) { System.out.println(arr[i]); }
i want to knw the correct solution...so, lets start step by step here itself, as this prog is not working in my blueJ!! x=1 so, arr[x++]=arr[1] ++arr[x++]= ++arr[2] =++6=7 (am i right?) +arr[x++]=arr[3]=8 so, the final answer is 7+8=15 is this right or wrong? |
|
| |
akshay Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:20 pm | |
| siya's right. i've also checked it |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:23 pm | |
| as_24...ok...but how is it done? i want explanation for the logic...i want to know how to solve it...thts y i asked whether my first step was right or wrong btw...y doesnt it work in my blueJ? its giving: [ expected |
|
| |
siya Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:25 pm | |
| hey anu see my previous post....dere i have xplained it!! |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:27 pm | |
| where yaar? i saw only ur answer...no explaination |
|
| |
akshay Active member
| Subject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:41 pm | |
| here's the program: int[]arr={2,4,6,8,10}; int x=1; arr[x++]=++arr[x++]+arr[x++]; for(int i=0;i<5;++i) { System.out.println(arr[i]); }
..and here's the working: x=1 arr[1]=++arr[2]+arr[3]; =in subscript 1 of arr[] =7+8=15 thats the calculation. ++arr[2] increments the value in subscript 2 of arr[]. so 1 is added to 6 to get 7. then under the 'for' construct values get printed on the output screen in order.so this is how the ouput goes: 2 15 7 8 10 |
|
| |
Anu..i luv icse...:) Active member
| Subject: Re: OUTPUT CONFUSION!! Sat Feb 21, 2009 1:14 am | |
| frm where u got 2 in the first line? i didnt understand |
|
| |
Sponsored content
| Subject: Re: OUTPUT CONFUSION!! | |
|
|
|
| |
|