(Error in the documentation)? Precedence problem math operator

Hello

I apologize in advance, I don't know (I'm a PHP and Perl programmer) of programming, I am fairly new to Java, so it's maybe a stupid question, but that's why I'm here. I hope that you will show me where my mistake so I can finally put this to rest before she drives me crazy :)
(Also, I hope I am posting this in the right forum?)

So I take a class in Java, and the question in duties related to the priority of the operand. When it comes with the addition and multiplication, division, things were fine, the documentation is clear and it is also logical math-wise (multiplication comes before the addition, etc. etc.).

However, we got this exercise to solve:

If you = 2, v = 3, w = 5, x = 7 and y = 11, find the value assuming that the int variables:

u ++ / v + u ++ * w


Now, according to the table of precedence of unary operator (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) the operator u ++ comes first, before the addition, division, and multiplication.

This means I could rewrite the exercise as:

((u+1) /v) + ((u+1) * w) = (3/3) + (4 * 5) = 1 + 20 = 21

However, if I run this in Java, the result I get is 15.


I tried to break the result for the two values in the Java code, so I could see where the problem is with my calculation.

For
System.out.println (/ v u ++);
I get 0

For
System.out.println ("u ++ * w");
I get 15

My teacher suggested that I have try to change the values of int to float, so I can see if the division came out to something illogical. I did, and now I get:

For
System.out.println (/ v u ++);
I have 0.66667

For
System.out.println ("u ++ * w");
I get 15.0000

That means that, for the first operation (division) division arrives on 2/3 (i.e. 0,6667) and then the u value is increased. In other words, operation u ++ is made after the division, not before. The same thing happens with the multiplication; When that is done, the value of u is now 3 (after what she has been raised by one in the previous operation) and the first to perform is the multiplication (3 * 5 = 15) and then only u ++.

It is completely against the documentation.


This is the script that I wrote to test the question:

public class MathTest {}
Public Shared Sub main (String [] args) {}
float u = 2, v = 3, w = 5, x = 7 and y = 11;
System.out.println ("initial 'u' value:" + u);
float tmp1 = u ++ / v;
System.out.println ("/ u v ++ =" + tmp1);
System.out.println ("first ++ 'u' value:" + u);
float tmp2 = u ++ * w;
System.out.println ("u ++ * w =" + tmp2);
System.out.println ("Second ++ 'u' value:" + u);
System.out.println (tmp1 + TMP2);
}
}


The output:

Initial value for 'u': 2.0
/ u v ++ = 1.0
First ++ value 'u': 3.0
u ++ * w = 20.0
Second ++ value 'u': 4.0
21.0

Obviously, the ++ is done after the division and multiplication.

Am I missing something here? Documentation is bad, or have I missed something obvious? It drives me crazy!

Thanks in advance,

Mori

>
Now, according to the table of precedence of unary operator (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) the operator u ++ comes first, before the addition, division, and multiplication.
>
You must use the specification of the Java language if you want to know the facts about operators such as the prefix and suffix.

15.14 postfix expressions
http://docs.Oracle.com/javase/specs/JLS/SE7/HTML/JLS-15.html#JLS-15.14

In accordance with the specification of the Java 15.14.2 language section
>
The value of the expression to postfix increment is the value of the variable before the new value is stored.
>
So, what is the value of u before the new value is stored? 2 - this is the value used in the expression.
>
That means that, for the first operation (division) division arrives on 2/3 (i.e. 0,6667) and then the u value is increased. In other words, operation u ++ takes place after the division, not before. The same thing happens with the multiplication; When that is done, the value of u is now 3 (after what she has been raised by one in the previous operation) and the first to perform is the multiplication (3 * 5 = 15) and then only u ++.
>
Exactly - you guessed it!
>
It is completely against the documentation.
>
FAKE! This is quite what the documents (my documents, not yours). The value is incremented AFTER the operation that uses it.

Tags: Java

Similar Questions

  • Errors in the documentation of the API in WebWorks

    Can we start a list of errors in the documentation? A couple I picked up so far:

    1. HTML5 File API is not supported by PlayBook. It was falsely announced that supported: https://developer.blackberry.com/html5/apis/filesystem.html
    2. FilePickerOptions filter the example values don't work property, you must precede the extensions with *, for example ["*.jpg", "*.bmp"]. https://developer.BlackBerry.com/HTML5/APIs/BlackBerry.Invoke.card.filepickeroptions.HTML#filter

    Thanks for catching these.

    Please feel free to log these errors using the Manager of public incidents and submit it to the "Documentation" project title: https://www.blackberry.com/jira/secure/Dashboard.jspa.

    We will be able to keep track of issues and resolutions, and since it is open to the public, users can check if their problems have been reported as well.

  • documentation error: convert the PID Gains

    There is an error in the documentation for the Convert PID Gains VI. In the table explaining the calculations for the parallel form, the documentation says (Ki = Ki') but the calculation of the VI is Ki = dT * Ki':

    nathand,

    I filed 595523 CAR to solve the conflicting equations.

    Daniel C.

    Technical sales engineer

  • Acer iconia a b3 - a30 errors after the system update

    Hi my Tablet conducted an update of the system. Everything is fine, but now I get errors for the portal app Acer and Opera app unexpected error please reboot if I restart the app it crashes again.

    Also is it possible to change ro_debuggable to 1, so I can use root adb shell thank you

    Robb

    Hi Robb,

    In regards to the error continues to Acer portal on your Acer device, I suggest that you can try to uninstall Acer Portal updates and reinstall by downloading the Acer Android portal according to its online help.

    If the problem persists, I will really appreciate if you could provide us with more information below. Thank you!

    1. Please send your comments via the portal Acer Acer BYOC applications support.

    2. Please capture that a screenshot of the error message occurs on the Acer site and we send it to the best solution.

    Acer BYOC Apps support

  • "Error - a problem prevented the document under analysis. Please try again, or to correct this information, see Help and Support or the documentation that came with the scanner"while trying to scan using HP G4050 on windows 7

    A problem prevented the document are analyzed. Windows 7 - HP G4050 scanner.
    I have a HP G4050 which worked fine with Vista.  After the upgrade to Windows 7, I get the following error when scanning:

    A problem prevented the document are analyzed.  Please try again, or to correct this information, see Help and Support or the documentation that came with the scanner.

    I get a different error during an attempt of an overview.  It starts to get an overview of the page, gets about 2 inches to the bottom of the page and then I get the following error:

    An error occurred when you set the properties of the scanner.  If another program is scanning, please wait to complete, and then try again.

    I downloaded the latest driver (and reinstalled several times) of HP with no luck.  No errors are recorded in the Application events.

    I'm going nuts trying to figure out this one!  Thanks for your help.

    BT

    Update:

    I finally had time to unplug the scanner, wait 60 seconds and then plug it again.

    Problem solved.

    Scan of stupid...

    BT

  • Error - the computer is running an operating system Microsoft Dynamics CRM does not support for the installation of the Extension of reporting Dynamics CRM 2011.

    Original title: Dynamics CRM 2011 Extension of reporting facility.

    Nice day

    Asked me to install this program called Extension Microsoft Dynamics CRM 2011 report Authoring on one of our PC network operations.  The computer is a Dell OptiPlex 960 under Windows XP SP3.  When attempting to install the program, you get the following error message:

    The computer is running an operating system Microsoft Dynamics CRM does not support.  To install this product, you need to upgrade your computer to an operating system supported.  For a complete list of supported operating systems, see the documentation for Microsoft Dynamics CRM (http://go.microsoft.com/fwlink/?LinkID=181018)
    For additional detals see logfile C:\Documents and Settings\bcodom\Application Data\Microsoft\MSCRM\Logs\BIDSExtensionsSetup.log

    Now, normally, I just coordinates with the end-user to him upgrade to Windows 7, however, after watching on the download page of this application (http://www.microsoft.com/download/en/details.aspx?id=13818), I noticed that Windows XP is one of the supported operating systems that can be installed on.  In addition, after looking around on the Technet documentation, I was not given a definitive answer on whether or not this application is not supported on Windows XP.

    So, my question is creation of Microsoft Dynamics CRM 2011 report Extension works on Windows XP SP3, or do we let us upgrade this computer to Windows 7?  Thank you!

    Hi Bcodom,

    In dealing with the problem to install the Extension of Microsoft Dynamics CRM 2011 report creation, I would recommend you to post your question in the help link.

    http://social.Microsoft.com/forums/en/CRM/threads

    Hope the helps of information.

  • opatch 10.1.2 Oracle Home - ERROR: OPatch failed due to problems in the area of patch.

    Hi all

    DB: 11.2.0.3.0

    EBS:12.1.3

    Operating systems: Solaris SPARC 64-bit

    I get the following error message on the command below:

    opatch $ apply - invPtrLoc $ORACLE_HOME/oraInst.loc

    Setup Oracle interim Patch version 1.0.0.0.64
    Copyright (c) 2011 Oracle Corporation. All rights reserved...

    Oracle recommends using the latest version of OPatch
    and read the OPatch documentation in the docs/OPatch
    Directory for its use. For more information on the last OPatch and
    other support issues, please refer to document ID 293369.1
    available on My Oracle Support (https://myoraclesupport.oracle.com)

    Oracle home: /d001/test1/apps/tech_st/10.1.2
    The Oracle Home Inventory: /d001/test1/apps/tech_st/10.1.2/inventory
    Inventory Center: / export/home/applmgr/oraInventory
    from: /var/opt/oracle/oraInst.loc
    YES location: /d001/test1/apps/tech_st/10.1.2/oui
    YES shared library: /d001/test1/apps/tech_st/10.1.2/oui/lib/solaris/liboraInstaller.so
    Location of Java: /d001/test1/apps/tech_st/10.1.2/jdk/jre/bin/java
    Location of the log file: /d001/test1/apps/tech_st/10.1.2/.patch_storage/ < patch ID > / *.log

    The patch directory field must be a number.

    ERROR: OPatch failed due to problems in the area of patch.

    $ opatch version

    Setup Oracle interim Patch version 1.0.0.0.64
    Copyright (c) 2011 Oracle Corporation. All rights reserved...

    Oracle recommends using the latest version of OPatch
    and read the OPatch documentation in the docs/OPatch
    Directory for its use. For more information on the last OPatch and
    other support issues, please refer to document ID 293369.1
    available on My Oracle Support (https://myoraclesupport.oracle.com)

    OPatch Version: 1.0.0.0.64

    Tried the underside of the notes but the error persists. Even tried several times 'p6880880_101000_SOLARIS64.zip' to download and unzip on the server, but of no use. This question took place now for a few days.

    (Error: OPatch failed due to problems in the area of the Patch [ID 1281504.1]).

    Opatch error: The Patch Directory area must be a number [258650.1 ID]

    O patch 1.0 . 0.0.55 fails with the error 'the Patch directory field must be a number' [ID 394601.1]

    Patch Directory area must be a number: Opatch returns with the Code error = 170 [369555.1 ID]

    Please let me know any other suggestion is appreciated as the runinstaller from Patch 5983622 -Upgrade to Forms 10 g OracleAS and statement 10.1.2.3 (437878,1) fails after running root.sh Run specific tasks.

    I'm upgrading to 10.1.2.3.0 forms using - reclassification OracleAS g 10 forms and States to 10.1.2.3 (437878.1)

    Thank you for your time

    Kind regards

    user10088255

    Hi user10088255,

    Please follow the procedure under the section 'How to check the contents of the inventory Central' (Doc ID 742477.1) to check whether or not 10.1.2 ORACLE_HOME is registered in the central inventory. If it is not registered then follow one of the methods in the same doc to add.

    Thank you

    Hussein

  • 6.2.16: when you try to update Itunes, I get the following error message: "there is a problem with this package of can I install."  A program required for this install to complete could not be run.  Contact your support team / packages vendo

    6.2.16: when you try to update ITunes on my Windows laptop, I get the following error message: "there is a problem with this Windows Installer package.  A program required for this teaching to complete could not be run.  Contact your supplier of staff or the package of support ".  There is no associated error code.  I've never had a previous issue with ITunes updates.  Thank you, Debbie

    Repair Apple Software Update since the programs & features Panel configuration and then try again.

    For general advice, see troubleshooting problems with iTunes for Windows updates.

    The steps described in the second case are a guide to remove everything related to iTunes and then rebuild what is often a good starting point, unless the symptoms indicate a more specific approach.

    Review the other boxes and other support documents list to the bottom of the page, in case one of them applies.

    The more information box has direct links with the current and recent if you have problems to download, must revert to an older version or want to try the version of iTunes for Windows (64-bit - for older video cards) as a workaround for problems with installation or operation, or compatibility with third-party software.

    Backups of your library and device should be affected by these measures but there are links to backup and recovery advice there.

    TT2

  • Ink cartridge error: refer to the Documentation of the printer

    I've scoured the forums for a solution to my problem and come up with nothing. I have a HP Photosmart C5250 all in one connected via USB to a Dell Inspiron under Windows 7 64-bit. I tried the reset suggested several times with no ink cartridges does not. I use HP brand ink cartridges. In its current form, I have no need to print anything but I need to scan something into my computer and the error message prevents me from doing anything. I've lived the documentation several times and he told me something that I already have his not know or is not already done.

    Hey SGibbons, lets try the following steps:

    1. without turning off the product, disconnect the USB cable (if connected like that) from the back of the product

    2. remove the cartridges from the product. Wait that a message to insert the cartridges. If you don't see a message in a few minutes, go to the next Ste.

    3. disconnect the power cord from the back of the product. Wait 60 seconds

    4 reconnect the power cord. If the product does not automatically turn on, press the power button

    5 reinsert the cartridges and close the doors on the product. If you are prompted to print a calibration page, do it.  If you disconnected the USB cable, plug it back in the back of the product

    6. try to reprint

    I would like to know if that helps at all. If it does not provide new details or error messages and we'll go from there.

    Thank you

    Sean

  • Printer does not work on the Windows XP computer, get the error message like "an error occurred during port configuration. This operation is not supported.

    Original title: 1. printer stopped communicating with the computer. 2 port - associated configuration error?

    I have a big problem. All of a sudden my printer - AIO Photo964 said he cannot communicate with my computer. The printer works fine. I tried switching cables USB, all the trouble shooting suggestions, etc. etc. Nothing works and it makes no sense. I can't print anything. I thought it would be that I installed a Seagate external hard drive backup, then I uninstalled the program - no help. ITunes installed recently, because she had changed the printer default, changed back - no help. The USB cable is not tight in the printer (or both cables, I tried), but AFAIK it's not new (?) And when I try to configure the port, I get the error message "an error occurred during port configuration. This operation is not supported"I have no idea what it means.  Can someone help me with this? I have to return a new printer? The USB port on the printer is repairable if this is the problem? How will I know? Who would do that?

    Thanks, I'd appreciate any help.

    It is always useful to have the complete error message without paraphrase.

    It also helps to identify the version of Windows you have, including service pack.

    And it helps to give the manufacturer of the printer in addition to the model.  In your case, I guess you have a Dell printer.  I know that some Dell printers are rebadged Lexmarks, but I don't know if it's a.

    Why you try to configure the USB port?  It cannot be configured - you've discovered.  It's normal.

    It's quite strange that an iTunes installation would have had something to do with the printers.  What printer was made by default after installing iTunes?

    You say you have tried another USB cable.  Have you tried using a different USB port on the computer? Have you checked in the Device Manager (start > run > devmgmt.msc > OK) to see if there is all the warning icons in the category "controllers of Bus USB?

    I suggest you uninstall the printer software and driver completely and reinstall by following the directions in Its first Article.

    Don't skip step 4.  After step 4 and step 5, follow these steps:

    Important: If you have a Lexmark printer, skip the following

    Open a command prompt window (start > run > cmd > OK)
    type the following in the black command prompt window, and then press ENTER after each line

    net stop spooler
    dependent on the spooler of sc config = RPCSS
    net start spooler
    output

    Note that there is no space before the = and there is a space after it.

    The Windows XP driver for the Dell Photo AIO 964 printer is here--> http://www.dell.com/support/drivers/us/en/04/DriverDetails/DriverFileFormats/Product/dell-964?DriverId=R113115&FileId=2731111743&urlProductCode=False

  • Error E0BB0147: the "Volume Snap" operation is not currently enabled for this Volume

    Hello!

    Since an update of my Windows XP at the end of 2011, I have problems on my HD using Ghost 14.0 backup. I get the following error message:

    -Impossible to create an image of the selected disk virtual volume.

    -E0BB0147 error: "Volume Snap" operation is not currently enabled for this Volume.

    What should I do to fix this?

    Thanking in advance for your help,.

    tico776

    Hello

    I suggest you to see link and check if it helps:

    Important: this section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs.

    For more information about how to back up the registry, see the link:

    Back up the registry

    http://support.Microsoft.com/kb/322756

     

    Error: "error E0BB0147: the 'Snap Volume' operation is not currently enabled for this Volume" when creating a backup using Norton Ghost 14.0

    https://www-secure.Symantec.com/Norton-support/JSP/help-solutions.jsp?LG=English&CT=United+States&docid=20080929121249EN&product=home&version=1&PVID=f-home

  • HP Photosmart 3110 referred to the documentation for the printer. Error 0xe18a001

    HP Photosmart 3110 referred to the documentation for the printer. Error 0xe18a001

    Hello caromuna,

    It seems that other users have found a way to completely reset the printer back to the default settings, which can help with this question.

    The reset is discussed in this forum thread and seems to be a bit difficult to fill. Let me know if it helps to solve your problem.

    Photosmart 3310 ink system failure

  • Problem area: windows update; Error: TRUST_E_NOSIGNATURE (0x800b0100) __Message: installation error prevented the service pack 2 windows systems (KB948465) _

    Problem area: windows update; Error: TRUST_E_NOSIGNATURE (0x800b0100)
    Message: Installation error prevented the service pack 2 windows systems (KB948465)

    http://support.Microsoft.com/kb/956702

    «Error message when you try to use Microsoft Update or Windows Update Web sites to install updates: «0x800B0100»»

    Method for Windows Vista or Windows Server 2008 to resolve this issue, run the tool (Checksur.exe) system update. To do this, follow these steps:

    1. Download and run the system update tool. This tool runs an ad hoc analysis of inconsistencies that might prevent future maintenance operations. For more information about how to download and run the Checksur.exe tool, click on the number below to view the article in the Microsoft Knowledge Base:

      947821 (http://support.microsoft.com/kb/947821/) Description of the update readiness tool for Windows Vista system
    2. Try to install updates again.

    http://support.Microsoft.com/kb/947821/

    "Description of the preparation tool system update for Windows Vista for Windows Server 2008 and for Windows 7"

    If the above solves the problem:

    It comes with Vista, upgrade install and activate Forum.

    You will get the best help for any problem of Update/Service Pack update Vista Forum; the link below:

    http://social.answers.Microsoft.com/forums/en-us/vistawu/threads

    When you repost here, kindly include this error Code, and exactly what is happening when you try to update.

    In this way, you will receive the best help.

    See you soon.

    Mick Murphy - Microsoft partner

  • Server connection error:-1 there is a problem connecting to the server... hp photosmart 5510

    HP photosmart 5510 e - while a printer B111a

    Windows vista 32-bit

    connection error message-Server error:-1 there was a problem connecting to the server, press Retry or ok to continue

    No changes have been made to my operating system

    Try to add new applications with eprint center of my Compaq Presario CQ60 laptop to my HP printer. Computer tells me that the new applications are there and ready to use, but printer says 'server connection error "? I followed all the instructions to connect to the wireless router, but I'm not sure how to connect to the "Server"?

    The steps below a usually resolve the problem you are experiencing:

    1. unplug the power cord at the back of the printer.

    2. unplug the power cord at the back of your router (and the modem, if they are separated from the router).

    3. wait 20 seconds, then plug the router (and the modem, if necessary) in.

    4. wait for 30 seconds, then plug the printer back and power.

    5. press the button on the front of the printer ePrint, and it should try to connect to Web Services again.

    These steps usually fix the problem, but if it persists, you can try definition of network information static for the printer (which is sometimes useful to stabilize the ability of the printer to get outside of your network to the internet):

    1. tap the wireless at the top of the screen of the printer and note the IP address.
     
    2. Enter the IP address in the address bar of a web browser on a computer and press on enter or click the go button browser.
     
    3. the printer status page must be open.  Click network in the upper part.
     
    4. click on networking on the left.
     
    5. Select the Proxy settings.
    Note: If you are prompted for a redirect, click OK.  If you receive a certificate warning, select the option that allows you to continue anyway.
    If you receive an internal system error, refresh the page until it loads the proxy settings.
     
    6. check that all fields are empty.  If they are not, make them disappear and make sure that the Proxy Server requires authentication is unchecked and click on apply.  You should get a success message.
     
    7. click on the network address (IP) on the left.
    Note: If you only configuring IP address and DNS address with a yellow note Configuration, refresh the page until it loads completely.
     
    8. leave automatic IP IP address Configuration.
     
    9 change the DNS address to the manual DNS Server Configuration.
     
    10. enter manual for the manual preferred DNS Server 8.8.8.8 and 8.8.4.4 for auxiliary DNS.
     
    11. click Apply and you should get a success message.
     
    12. turn off the printer for 30 seconds and then turn it on again to force the new settings take effect.

    Let me know if you have any additional questions. Thank you!

  • When you try to copy a .jpg file in another folder I get an error "unexpected error prevents the operation."

    This is the error I got trying to copy a .jpg file in a different folder.

    An unexpected error prevented the operation. Make a note of this error code, which might be useful if you get additional help to resolve this problem:

    Error 0 x 80070021: the process cannot access the file because another process has locked a portion of the file.

    Any help is very appreciated.

    This is the error I got trying to copy a .jpg file in a different folder.

    An unexpected error prevented the operation. Make a note of this error code, which might be useful if you get additional help to resolve this problem:

    Error 0 x 80070021: the process cannot access the file because another process has locked a portion of the file.

    Any help is very appreciated.

    Apparently, Windows has a problem to download files larger than 50 MB.  To resolve this issue, follow these steps:

    In a security update, Microsoft has limited the size of files that can be downloaded from the remote folders to 50 MB. To increase this, you must change a registry setting.

    1. Download FileSizeLimit.reg
    2. Double click on FileSizeLimit.reg
    3. If necessary, enable the registry editor to run
    4. Click the Yes button to allow the changes need to be made
    5. Click OK
    6. Restart your computer

    For more information, please see the Microsoft article 900900 Knowledge Base.

Maybe you are looking for

  • How to recover bookmarks - cannot add, restore files or import even after restarting the pc and remove reinstall Firefox?

    Bookmarks have disappeared. Cannot add new bookmarks, import from another browser, open the previous bookmarks file. I tried the solutions in Help and troubleshooting without success. CCleaner doesn't work anymore when it comes to Firefox. I've used

  • Satellite Pro L300 - cannot use Intel ProSet WLan tool with Win XP

    Hello! I have the same problem. I installed a XP SP3 and I can't use the * Fn + F8 * hotkey to activate the WLAN function on or off. Other Fn keys work correctly. The WiFi network also works, but it can be used by the built-in Windows. Intel ProSet o

  • Numlock at startup

    Hi, I'm trying to find how to activate the NumLock to be on the start up. Looked in the BIOS and no setting for lock seen at all, on references from Web site to the evolution of the value 1 or 2 in the HKEY_USERS\Default\Control Panel\Keyboard but my

  • How to get bookmarks bar back?

    I just upgraded from 10.6.8 to 10.11, I imported by Favorites, but I can't them upstairs. They are along the coast, I don't like them out there, it's much easier for me to use the old bar in front. So, how do them across the top once again?

  • Updated to ios 9.2

    Now when I press the music, 'Apple Music' screen is displayed and does not disappear. Cannot get my music more. What gives? Am I supposed to put something?