Execution from right to left : a=b=c;

Help!
I am using a tutorial to study for the certification exam.
Unfortunately, I do not understand the answer of a very simple question.
Can you give me a hand on this one?
************* This is the Question of the tutorial ************************************
After the execution of the code-fragment below, what will be the values of i and a?
1.     public class CalcMe {
2.     public static void main(String[] args) {
3.     int [] b = {3,7};
4.     int i = 2, a = 4;
5.     b[i] = i = 0;
6.     a += b;
7.     }
8.     }
Answer 1 i: 0 a: 11
Answer 2 i: 0 a: 4
Answer 3 i: 3 a: 4
Answer 4 An exception is thrown
Answer 5 None of the above
************* This is the Answer to the Question of the tutorial ************************************
After the execution of the code-fragment below, what will be the values of i and a?
1. i: 0 a: 11
2. i: 0 a: 4
3. i: 3 a: 4
4. An exception is thrown
5. None of the above
Answer 4 is correct, an ArrayIndexOutOfBoundsException is thrown at line 5. The value of i
evaluated from the right hand side to the left, it is element b[2] that should get a value assigned,
arrays in Java starts from 0, element 2 is out of scope.
*************************** This is my answer *********************************************************
Despite I read the answer (and created and run it) I still do not understand how line 5 is executed because it seems
that the expression is evaluated from left to right instead of right to left.
I believe that correct answer should be:
in line 5. b[i]=i=0 if expression is executed from right to left then
first i=0 and after that b[0]=0
which leads to believe that the values for i & a will be : i=0 a=4
[Copied from Complete Java 2 Certification Study Guide ISBN 0-7821-4077-7 Phillip Heller & Simon Roberts Chapter #2 Operators and Assignments Page 66]
Given three int varibles a,b,c, the statement a=b=0; is entirely legal. It is executed from right to left,
so that first 0 is assigned into variable c. After it has been executed, hte expression c=0 takes the value
that was assigned to the left side - that is 0. Next, the assignment of b takes place, using the value of
the expression to the right to the equal sign-again, 0. SImilarly, that expression takes the value that was assigned ,
so finally the variable a is also set to 0.
I'd appreciate an explanation

Does this mean that the assignment of indexes in arrays have higher priority than assignment operations?
in other words,
b[2]= ...whatever
will happen before anything else is evaluated in the right side of the expression.
Is that right?
Bingo. Section [url
http://java.sun.com/docs/books/jls/second_edition/html/
xpressions.doc.html#5295]15.26.1:"If the left-hand operand expression [of a simple
assignment operator] is an array access expression
(15.13), then many steps are required:
# First, the array reference subexpression of the
left-hand operand array access expression is
evaluated. If this evaluation completes abruptly, then
the assignment expression completes abruptly for the
same reason; the index subexpression (of the left-hand
operand array access expression) and the right-hand
operand are not evaluated and no assignment occurs.
# Otherwise, the index subexpression of the left-hand
operand array access expression is evaluated. If this
evaluation completes abruptly, then the assignment
expression completes abruptly for the same reason and
the right-hand operand is not evaluated and no
assignment occurs.
# Otherwise, the right-hand operand is evaluated. If
this evaluation completes abruptly, then the
assignment expression completes abruptly for the same
reason and no assignment occurs."
It then goes on to detail null checks on the array
reference, ArrayIndexOutOfBoundsException checks, etc.

Similar Messages

  • Transferring the negative sign from Right to Left for a currency field.

    Hi All,
    I am trying to transfer the negative sign in a currency field from right to left but in doing that i am not getting the comma seperators of the currency field.
    For eg : If the value is 12,345,678.00- then after converting it i am getting it as
    -12345678.00 and i am loosing the commas.
    I am trying to transfer the negative sign by first converting the currency field into character field.
    Kindly help for the same.
    Thanks,
    Sharadendu

    Hi,
    Use FM CLOI_PUT_SIGN_IN_FRONT.
    Try this code as well
    data: var(10),
    length type i.
    var = '300-'.
    write var.
    length = strlen( var ).
    length = length - 1.
    replace first occurrence of '-' in var+length(1) with ''.
    concatenate '-' var into var.
    write:/ var.
    Regards,
    Satish
    Message was edited by:
            Satish Panakala

  • Move an animator object from right to left

    How do I move an animator object from right to left?  I tried using the value with a minus sign in front of it. (i.e. -(xcoord) )  Please help.
    Thanks,
    Chris

    After you create the animator, click on it on the panel, you will see a rectangle. You can drag the rectangle to bigger or smaller. The graphic will be moving inside of this rectangle. In this rectangle, bottom left corner is x0 y0.  Top right cornet is x100, y100.
    Ryan Shi
    National Instruments
    Attachments:
    process1.zip ‏1 KB

  • I can't click below the toolbar .half inch to 3inch from right to left. all words or letters are not working. please help to resolve this problem. thanks!

    Everytime I open firefox, all words or letters below the toolbar half inch to 3 inch from right to left are not clickable(not working). but they are working or clickable on google crhome or internet explorer. please help to resolve this problem. thanks!

    The '''''Yahoo! Toolbar''''' and the '''''Babylon''''' extension have been reported to cause that problem. They seem to invisibly extend downward over the top of the web page display area. Disable or uninstall those add-ons.
    *See --> http://support.mozilla.com/en-US/kb/Uninstalling+add-ons
    *See --> http://support.mozilla.com/en-US/kb/Cannot%20uninstall%20an%20add-on
    *See --> http://kb.mozillazine.org/Uninstalling_toolbars
    *See --> https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *Adobe Shockwave for Director Netscape plug-in: [https://support.mozilla.com/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *Adobe PDF Plug-In For Firefox and Netscape: [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *Shockwave Flash (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *Next Generation Java Plug-in for Mozilla browsers: [https://support.mozilla.com/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

  • I need help for Arabic Typing in Pages and PhotoShop and how can I change the Typing Direction to Be from right to left

    Hi there
    Accualy I have 2 problems with Pages
    1- How can I get more Arabic Fonts with More Decorated style
    2- The typing in Arabic should be from right to left and in Pages it's Happining but the typin marker is not doing this so its hard to fix any mistakes in the middel of the paragraph.
           - how to change the alignment from left to right (Ctrl + Shift in MO Word) to do the hall text from right to left not only the paragraph Icon
    I think this will afect the other application Im using If some one help me with it.

    "Many" is an exageration, you can count R to L languages on one hand.
    Mostly they are used in countries which try not to pay for their software, and seem to have a pretty shoddy printing industry, so not much incentive for developers.
    However Arabic is a major language and Apple should fix the problem.
    As Tom suggests try Mellel, which is the best solution on the Mac.
    Adobe has ME versions of both Indesign and Photoshop, for which you pay extra. They mostly work well.
    MsWord for Windows (not the Mac) does reasonably well, but I have not tried its DTP features with Arabic so can't vouch for how solid they are in Word.
    Peter

  • When I write in hebrew from right to left the periods/quotation marks/question marks at end of sentences jump to the beginning of the sentence. help

    I cannot seem to format a message correctly when I write in hebrew from right to left
    even if I press left margin and the message starts from the left side, all question marks, and end of sentences (periods, etc) jump to the front of the sentence and quotation marks or separation marks (such as dashes) split up the lines and jump words to the front of the sentence.
    how can I change the formatting to solve this so the recipient receives a properly formatted email?

    are you using in bidi add-on?
    https://addons.mozilla.org/en-US/thunderbird/addon/bidi-mail-ui/

  • Please, I need help in this,How to make a tree control appear from right to left ??

    i working on Arabic project in which we use a tree control and i  want it to display its branches from right to left .
    i tried to rotate it but it doesn't work because the disclosure triangle still appear on the left .
    i ask if there is any thing to mirror the tree control ,and ask if this mirroing will work or not?

    You'll need to modify the layout logic of your renderer.
    Here's a simple example that extends the default tree renderer and overrides the updateDisplayList method(). It will probably need more work. Set textAlign="right" on your Tree control when you use this renderer. You'll also need to supply a disclosure icon that points in the opposite direction.
    package
        import mx.controls.treeClasses.TreeItemRenderer;
        import mx.controls.treeClasses.TreeListData;
        public class RightToLeftTreeItemRenderer extends TreeItemRenderer
            override protected function updateDisplayList(unscaledWidth:Number,
                                                      unscaledHeight:Number):void
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                var startx : Number = data ? TreeListData( listData ).indent : 0;
                startx = unscaledWidth - startx;
                if ( disclosureIcon )
                    disclosureIcon.x = startx - disclosureIcon.width;
                    startx = disclosureIcon.x;
                if ( icon )
                    icon.x = startx - icon.width;
                if ( label )
                    label.x = 0;

  • How can i display at  JTextArea from right to left

    how can i display at JTextArea from right to left?
    i try to write setAlignmentX(JTextArea.RIGHT_ALIGNMENT)
    but this not help,
    thanks for help.

    use this
    JTextArea.applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);

  • How to shift Negative sign from Right to left

    Hi friends,
    please tell me How to shift Negative sign from Right to left for quan data type i am getting on right side but i want to display it on left exactly preceding my output number display.

    hi yogesh
    check this function module..
    <u><i><b>CLOI_PUT_SIGN_IN_FRONT</b></i></u>
    this will move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all character fields), not right justifed as numbers normally are.
    chck this example..
    data: a1 type i value 56 ,
    a2 type i value 60,
    res type i.
    res = a1 - a2.
    data: res1(10).
    res1 = res.
    CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
    CHANGING
    VALUE = res1
    write res1.
    I<u><i><b>MPORTANT</b></i></u>
    You can use this FM CLOI_PUT_SIGN_IN_FRONT.
    But you need to declare the amount field as char.
    Or you can code like this
    data int type i.
    data char(10).
    int = -4.
    int = int * -1.
    write int to char.
    concatenate '-' char into char.
    reward if useful..
    Message was edited by:
            navjot sharma

  • How to arrange button on jtoolbar from right to left instead of LTR

    Hi
    Thank you for reading my post.
    I tried to use
    setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);on a toolbar to force it to arrange buttons from right to left , but it still use left to right
    can some one please help me about this ?
    how i can force it to show buttons from right to left?
    Thanks

    aren't you lucky, someone else with the exact same problem
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=013272

  • I need to create Arabic and Farsi brochures in InDesign CS6. Does anyone know where I can get a plug-in to make Middle Eastern languages work correctly from right to left?

    I need to create Arabic and Farsi brochures in InDesign CS6. Does anyone know where I can get a plug-in to make Middle Eastern languages work correctly from right to left?

    With CS6 you have to pay extra for these plugins.
    With the CC you can download different ME versions to add their functionality.

  • Premiere Elements 13 - how to write Hebrew from  right --- to  left?

    I can see Hebrew fonts, but I can`t write Hebrew from right to left. Thanks!

    LAJRS
    I have not been involved in languages for Premiere Elements other than English. What I have been reporting to you relates
    to from what I have read.
    Your chances for obtaining the right to left text in Photoshop CS6 are likely to be good.
    On the video end of things, there was a report of a workaround with text generated in another program and then copy paste
    into the Premiere Pro Titler.
    http://www.clasener.eu/arabic-premiere-pro-solve/
    CreativeCOW
    I am not sure if that concept could be extended to Premiere Elements and its Titler.
    ATR

  • Slide toggle from right to left and left to right. in sharepoint issue.

    I have used this url to create asp.net sliding panel but panel slides and while page is loading it will dissappear.
    link
    how to solve it.
    my code:
     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type='text/javascript'></script>
        <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    $(".myButton").click(function () {
    // Set the effect type
    var effect = 'slide';
    // Set the options for the effect type chosen
    var options = { direction: $('.mySelect').val() };
    // Set the duration (default: 400 milliseconds)
    var duration = 500;
    $('#myDiv').toggle(effect, options, duration);
    </script>
    /** Style for the body **/
     body {
        font: 12px Tahoma, Arial, Helvetica, Sans-Serif;
    /** Style for the button & div **/
     .myButton {
        padding: .2em 1em;
        font-size: 1em;
    .mySelect {
        padding: .2em 0;
        font-size: 1em;
    #myDiv {
        color:Green;
        background-color:#eee;
        border:2px solid #333;
        display:none;
        text-align:justify;
    #myDiv p {
        margin: 15px;
        font-size: 0.917em;
    /** Style for the cointainer **/
     #body {
        clear: both;
        margin: 0 auto;
        max-width: 534px;
    html, body {
        background-color:White;
    hr {
        margin-bottom:40px;
    <div id="body">
    <h2>Slide toggle from right to left and left to right.</h2>
        <hr/>
        <p>
            <select class="mySelect">
                <option value="right">Right</option>
                <option value="left">Left</option>            
                <option value="up">Up</option>
                <option value="down">Down</option>
            </select>
            <button id="button" class="myButton">Run Effect</button>
        </p>
      <div id="myDiv">
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard d still in their infancy. Various versions have evolved over the years, sometimes by
    accident, sometimes on purpose (injected humour and the like).</p>
        </div>
    </div>
    Thanks.

    Hi ,
    Vincent Han thanks for ur reply.
    this is my latest code but still not working.
    having same issue : panel is about to slide but as soon as page gets refreshed it starts sliding and return on ppage as it is.
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            #img1
                background: green;
                width: 100px;
                height: 100px;
                outline: 1px solid #f93;
            /** Style for the body **/
            body
                font: 12px Tahoma, Arial, Helvetica, Sans-Serif;
            /** Style for the button & div **/
            .myButton
                padding: .2em 1em;
                font-size: 1em;
            .mySelect
                padding: .2em 0;
                font-size: 1em;
            #myDiv
                color: Green;
                background-color: #eee;
                border: 2px solid #333;
                text-align: justify;
            #myDiv p
                margin: 15px;
                font-size: 0.917em;
            /** Style for the cointainer **/
            #body
                clear: both;
                margin: 0 auto;
                max-width: 534px;
            html, body
                background-color: White;
            hr
                margin-bottom: 40px;
        </style>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type='text/javascript'></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $(".myButton").click(function () {
                    // Set the effect type
                    var effect = 'slide';
                    // Set the options for the effect type chosen
                    var options = { direction: $('.mySelect').val() };
                    // Set the duration (default: 400 milliseconds)
                    var duration = 500;
                    $('#myDiv').toggle(effect, options, duration);
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="body">
            <h2>
                Slide toggle from right to left and left to right.</h2>
            <hr />
            <p>
                <select class="mySelect">
                    <option value="right">Right</option>
                    <option value="left">Left</option>
                    <option value="up">Up</option>
                    <option value="down">Down</option>
                </select>
                <button id="button" class="myButton">
                    Run Effect</button>
            </p>
            <div id="myDiv">
                <p>
                    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
                    Ipsum has been the industry's standard dummy text ever since the 1500s, when an
                   .</p>
                <p>
                    It is a long established fact that a reader will be distracted by the readable content
                    of a page when looking at its layout. The point of using Lorem Ipsum is that it
                    has a more-or-less normal distribution of letters, as opposed to using 'Content
                    here, .</p>
            </div>
        </div>
        </form>
    </body>
    </html>

  • How do I get text to go from right to left in Creative Cloud?

    I need to create Arabic and Hebrew content in the Creative Cloud version of Adobe Illustrator, however, I can't seem to get the content to paste from my source document from right to left. 

    Still having trouble using Indic-support.  Tried that before posting question.  However, found a "better way", at least for me.  I copied the text to Microsoft Word, then opened the Word Document with Illustrator (which I didn't know I could do - found it in a note somewhere).  Cut and paste was very easy after that.  I was able to finish my project within a similar amount of time as I can with other languages.  It takes a few more steps than direct copy and paste, but not much from a time perspective!  It works! Hooray!

  • Reading a file line by line from right to left using StringTokenizer

    I hope the title caught you attention!!!
    I am a little stuck. How can I implement a method that will allow me to read a sentence from right to left when reading from file.
    Ex.
    IX: Series      {2}
    IX: {Series!geometric|(}      {4}
    IX: {Euler's constant}      {4}
    IX: {Series!geometric|)}      {4}
    IX: {Series!arithmetic|(}      {4}
    IX: {Series!arithmetic|)}      {5}
    IX: {Series!harmonic|(}      {5}
    IX: {Euler's constant}      {5}
    IX: {Series!harmonic|)}      {5}
    IX: Series      {5}
    So for example in the first row we have
    IX: Series      {2}
    and what the output should show be is
    Series: 2
    What happens in the background is that I created an entry for a TreeMap which will be display at the end.
    Thanks for your time and appreciate your help kindly.

    Well, as a left-to-right start:
    public class TopicInputReader extends BufferedReader {
        public static final int STARTTOPIC = 0;
        public static final int ENDTOPIC   = 1;
        public static final int SUBTOPIC   = 2; 
        // Instead of making Topic members public, you should make accessors.
        // Didn't feel like typing.
        public class Topic {
            public int    type; // STARTTOPIC, ENDTOPIC, or SUBTOPIC
            public String name;
            public String parent;
            public int    page;
        public TopicInputReader (Reader in) {
            super(in);
        public TopicInputReader (Reader in, int sz) {
            super(in, sz);
        public Topic readTopic () throws IOEXception {
            String          line;
            Topic           topic;
            StringTokenizer tokens;
            String          token;
            line = readLine();
            if (line = null) throw new EOFException();
            tokens = new StringTokenizer(line);
            topic.parent = "".intern();
            // Note: If StringTokenizer isn't appropriate for you, you
            // can use a StringReader in conjunction with a StreamTokenizer.
            // Ex: token = new StreamTokenizer(new StringReader(line));
            // TODO: Set up tokenizer parameters here.
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken(appropriate_delimiter);
                // TODO: Fill in 'topic' fields here.
                // Keep in mind, since you're reading left-to-right and you don't
                // know if a particular string is going to be a topic name or a
                // sub topic, you can always just read a topic name into topic.name
                // and, when you encounter a new topic name:
                //    topic.parent += ('!' + topic.name);
                //    topic.name = token;
            return topic;
    };I definitely have not tested that... or even double-checked it.
    Although... the format of your topic list file does lend itself well to right-to-left parsing. Since you are insisting, I suggest reversing the string and using a StringTokenizer (or a StreamTokenizer and a StringReader):
        BufferedReader  r = new BufferedReader(new InputStreamReader(myInputStream));
        String          line, revline;
        StreamTokenizer tokens;
        while (...) {
            line    = r.readLine();
            revline = (new StringBuffer(line)).reverse().toString();
            tokens  = new StreamTokenizer(new StringReader(line));
            // Parse tokens here.
        };Jason

Maybe you are looking for

  • My iPhone 4 will not complete a back up. Error - 5000 comes up

    Error 5000 appears after "preaparing phone for back up" completes. "Continuing will result in the loss of all contents of this phone" is the message. Phone will not complete a synch and iTunes often goes into "Not responding". I have repaired iTunes

  • Non-ISP DDNS with Apple DHCP and DNS Services

    I have two questions about Dynamic DNS (DDNS) as it applies to Apple's DNS and DHCP services within my home network. I am not talking about DDNS in the context of making my external-facing router available by a domain name on the Internet using the d

  • I used to run this scrip before updating my FireFox and it worked fine, now it is not working, plz help javascript:%20void%200

    I used to use this Java Scrip before updating my FireFox now its not working, the script is as under javascript:%20void%200 this script open more then 50 pages in sequence as per the http addresses given on few web pages. please help

  • How to pass a paramter to a schedued process flow

    I have a process flow with a one varchar type parameter. I want to schedule this process flow and for that I have created a schedule and then attached it to the process flow using Process Flow -> Configuration -> Referred Calendar Option. Now my issu

  • ORA-01578 - bad blocks.

    Hello, We had a SAN crash last month and with all the confusion I missed that we had some bad blocks after the crash. Our RMAN backups have now aged out so we don't have a RMAN backup. What I do have is a datapump backup from before the event. This i