The Artima Developer Community
Sponsored Link

Java Answers Forum
About operation"+++++"

2 replies on 1 page. Most recent reply: May 8, 2003 6:16 AM by James Patterson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Saint Jerry

Posts: 1
Nickname: pretender
Registered: May, 2003

About operation"+++++" Posted: May 5, 2003 10:06 PM
Reply to this message Reply
Advertisement
There is a simple program but that is too diffeicult
for me to think out.Please explain it to me.

public class One{
public static void main(String args[]){
int i=1,j;
j=i+++++i;
System.out.println("i="+i+" j="+j);
}
}
Why this program can not pass compiler? But when I
change this sentence "j=i+++++i" to "j=(i++)+(++i)" or
"j=i+++(++i)",I just can get the right result. However
I cannot pass compiler as I change "j=i+++++i" to
"j=(i++)+++i". Why?


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: About operation"+++++" Posted: May 5, 2003 10:13 PM
Reply to this message Reply
Why do you want to write such horrible stuff? Even if you get some variation of this to work, it just makes for code that confuses the reader. The purpose of code is to comunicate to other people, otherwise we'd all just write machine code instead of easier-to-understand languages like Java, Python, C#, etc.

James Patterson

Posts: 16
Nickname: jmep
Registered: Mar, 2003

Re: About operation"+++++" Posted: May 8, 2003 6:16 AM
Reply to this message Reply
i+++++i is too ambiguous. exp++ has a higher precedence than ++exp and +. Therefore your compiler will see something like (i++)++ + i and this is invalid syntax. However, if you use i+++(++i) then it sees i++ + ++i because you are forcing the ++i grouping to be seen first and it can figure out i+++.

See: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html

Flat View: This topic has 2 replies on 1 page
Topic: Stuck & project due soon!  HELP!!! Previous Topic   Next Topic Topic: paint() vs repaint() vs update() ???

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use