Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Array question - enthuware

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I do not understand this syntax...

 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Martins wrote:Hi

I do not understand this syntax...




why ?



 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey here doesnt assigning b to a will change the value of a...i mean
a=b will be evaluated thus a will be {2,3,1,0}

thus the expression would be {2,3,1,0}[{2,3,1,0}[3]]...isnt it.

i know there is something wrong

please correct me
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:hey here doesnt assigning b to a will change the value of a...i mean
a=b will be evaluated thus a will be {2,3,1,0}

thus the expression would be {2,3,1,0}[{2,3,1,0}[3]]...isnt it.

i know there is something wrong

please correct me



That was the main funda in this question, everybody in starting thinks like you think, even I thought that way, but after running the example I got it that it is evaluating in different way, means left a evaluated before a=b is evaluated. It has some relationship with array expression evaluation. We need to discuss it further.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


what do you think will be the answer?

100 or 90?
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this part of the JLS...
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:

what do you think will be the answer?

100 or 90?



90
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes the answer is 90...what i meant is that this works not only for arrays.....gotto look at the jls link ankit gave
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:yes the answer is 90...what i meant is that this works not only for arrays.....gotto look at the jls link ankit gave



But the JLS topic itself is saying

15.13.1 Runtime Evaluation of Array Access



And I had also said the it has relation with Array expression evaluation.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes punit you were right but what explains x*(x=y) expression?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:yes punit you were right but what explains x*(x=y) expression?



That is a simple expression that follows left to right evaluation. Array expression are bit complex.
But why did you say this?

hey here doesnt assigning b to a will change the value of a...i mean
a=b will be evaluated thus a will be {2,3,1,0}

thus the expression would be {2,3,1,0}[{2,3,1,0}[3]]...isnt it.

i know there is something wrong

please correct me


 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh yes left to write....i remember it said first all the operands are calculated from left to right and then operations are done.....thanks a lot....

hey when i wrote that i had not read the jls document
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great healthy discussion of topic is good thing to remember the concepts for long terms.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we have to learn a language we have to speak it....that is why i love javaranch
 
Ankit Garg
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:oh yes left to write....


Left to Right

(I hope you don't think I'm trying to piss you off, I try to find any opportunity to make a joke )...
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hahaha.....
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:if we have to learn a language we have to speak it....that is why i love javaranch



Good you are getting enough time to discuss it, in between from March to October I did not get time to discuss anything on javaranch due to my cumbersome job, now after changing my job I am getting enough time.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why would this print 90? Wouldn't expression within brackets(x=y) have precedence over *?

Thanks
Chintan.
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chintan writes:
Why would this print 90? Wouldn't expression within brackets(x=y) have precedence over *?



Hi chintan, printf statement evaluates from left to right, hence first value of x is 9 and after assignment x is 10 hence answer is 90.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Punit Singh wrote:

Ankur kothari wrote:hey here doesnt assigning b to a will change the value of a...i mean
a=b will be evaluated thus a will be {2,3,1,0}

thus the expression would be {2,3,1,0}[{2,3,1,0}[3]]...isnt it.

i know there is something wrong

please correct me



That was the main funda in this question, everybody in starting thinks like you think, even I thought that way, but after running the example I got it that it is evaluating in different way, means left a evaluated before a=b is evaluated. It has some relationship with array expression evaluation. We need to discuss it further.



" a [ (a = b)[3] ]
a [ b[3] ]
since b[3]=0
hence a[0] i.e 1 will be the answer
"

 
Ankit Garg
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"harish gowda Java green" please check your private messages for some administrative matter.
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rohan.

Regards,
Chintan
 
Ranch Hand
Posts: 41
Mac OS X Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rohan yadav wrote:

Chintan writes:
Why would this print 90? Wouldn't expression within brackets(x=y) have precedence over *?



Hi chintan, printf statement evaluates from left to right, hence first value of x is 9 and after assignment x is 10 hence answer is 90.



Hey From Where this printf came here..?? I think It was println().
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic