Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   What is the logic of the output of this program? (https://www.askmehelpdesk.com/showthread.php?t=828639)

  • Nov 7, 2016, 07:11 PM
    PeytonPhelps
    What is the logic of the output of this program?
    public class Main
    {
    public static void main(String[]args)
    {
    int y = 12;
    int z = 0;

    for (int index = 0; index <= y; index++)
    {
    if ((index % 3 == 0) && (index % 2 == 0))
    {
    z--;
    }
    else
    {
    z++;
    }
    }
    System.out.println(z);
    }

    Does Java go through the (index % 3 == 0) & (index % 2 == 0)
    or just the first one - (index % 3 == 0)?


    I don't know.. lol.

  • All times are GMT -7. The time now is 09:07 PM.