Complete IIT AIEEE ICSE ISC PMT help forum
This is a free help Forum for Indian Students.
Complete IIT AIEEE ICSE ISC PMT help forum

Complete help forum for students preparing for icse iit aieee cbse pmt and other related exams.Stay updated about all 2011 exams.
 
HomeHome  PortalPortal  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  India NewsIndia News  
Keywords
Latest topics
Top posters
abhas
 
Anu..i luv icse...:)
 
G-7
 
siya
 
Candy
 
jOhNy
 
Apurva
 
WinRrule
 
ambili
 
saif
 



Search if you can't find it here

OUTPUT CONFUSION!!

View previous topic View next topic Go down
Go to page : 1, 2  Next
AuthorMessage
jOhNy
Active member
Active member
avatar


PostSubject: OUTPUT CONFUSION!! Sat Jan 31, 2009 3:28 pm

hullo frndz... Cool
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 pale pale Mad Mad
so plzz help..
thnxx a lot. afro
Back to top Go down
View user profile
jOhNy
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Fri Feb 06, 2009 8:35 pm

someone plzz help!!
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Sun Feb 08, 2009 11:49 am

no......jony de answer is
2 15 7 8 10
Back to top Go down
View user profile
jOhNy
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Sun Feb 08, 2009 5:04 pm

how come siya??
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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.
Back to top Go down
View user profile
monika

avatar


PostSubject: Re: OUTPUT CONFUSION!! Mon Feb 09, 2009 3:48 pm

ya siya's right
Wink
Back to top Go down
View user profile
akshay
Active member
Active member



PostSubject: 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
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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!!!!!!!!!
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Sat Feb 14, 2009 1:30 pm

hey!!!!! ne1.plz....check it n confirm
Back to top Go down
View user profile
akshay
Active member
Active member



PostSubject: Re: OUTPUT CONFUSION!! Sun Feb 15, 2009 2:38 am

sorry, my mistake=P
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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...
Back to top Go down
View user profile
jOhNy
Active member
Active member
avatar


PostSubject: 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?
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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....
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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
Back to top Go down
View user profile
jOhNy
Active member
Active member
avatar


PostSubject: 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...
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: 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
Back to top Go down
View user profile
jOhNy
Active member
Active member
avatar


PostSubject: 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
Back to top Go down
View user profile
Anu..i luv icse...:)
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 8:55 pm

hey...

i copy pasted this program...it is not working in my blueJ!!!!
Back to top Go down
View user profile
Anu..i luv icse...:)
Active member
Active member
avatar


PostSubject: 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!! Very Happy

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?
Back to top Go down
View user profile
akshay
Active member
Active member



PostSubject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:20 pm

siya's right. i've also checked it
Back to top Go down
View user profile
Anu..i luv icse...:)
Active member
Active member
avatar


PostSubject: 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
Back to top Go down
View user profile
siya
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:25 pm

hey anu see my previous post....dere i have xplained it!!
Back to top Go down
View user profile
Anu..i luv icse...:)
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Fri Feb 20, 2009 9:27 pm

where yaar? i saw only ur answer...no explaination
Back to top Go down
View user profile
akshay
Active member
Active member



PostSubject: 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
Back to top Go down
View user profile
Anu..i luv icse...:)
Active member
Active member
avatar


PostSubject: Re: OUTPUT CONFUSION!! Sat Feb 21, 2009 1:14 am

frm where u got 2 in the first line?

i didnt understand Evil or Very Mad
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: OUTPUT CONFUSION!!

Back to top Go down

OUTPUT CONFUSION!!

View previous topic View next topic Back to top
Page 1 of 2Go to page : 1, 2  Next

Permissions in this forum:You cannot reply to topics in this forum
Complete IIT AIEEE ICSE ISC PMT help forum :: Exam papers & Model test papers :: ICSE / ISC exam papers and model test papers-