Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:47:19+00:00 2026-06-03T09:47:19+00:00

Looking at the output of this particular method is confusing to me. I’m trying

  • 0

Looking at the output of this particular method is confusing to me. I’m trying to understand exactly what it’s doing.

This is the method:

for (int i = 0; i < 4; i ++) {
    for (int j = 0; j < 9; j++) {
    if (j==5) {
        break;
    }
    if ((j==0) || (i==0)) {
        continue;
    }
    if (!((j*i % 3) != 0)) {
    System.out.println(j*i);
    }
}

}

I know what the output is but I’m still not sure how it’s working, which is why I am asking here. So, This method will go through j until it reaches 5, then it breaks.

Then it increments i, j is 0. J != 5 so it doesn’t break, j == 0 so continue
But then J becomes 3 and I is 1. This is where I’m lost. Where did 3 come from??

I was using this to print out what was going on behind the scenes

    public static void tester() {
    for (int i = 0; i < 4; i ++) {
        for (int j = 0; j < 9; j++) {
            if (j==5) {
                System.out.println("j == 5, breaking");
                break;
            }
            if ((j==0) || (i==0)) {
                System.out.println("J is " + j);
                System.out.println("I is " + i);
                System.out.println("j or i == 0, continuing");
                continue;
            }
            if (!((j*i % 3) != 0)) {
                System.out.println("J is " + j);
                System.out.println("I is " + i);
                System.out.println(j*i);
            }
        }
        System.out.println();
    }
}

And the output is as follows:

J is 0

I is 0

j or i == 0, continuing

J is 1

I is 0

j or i == 0, continuing

J is 2

I is 0

j or i == 0, continuing

J is 3

I is 0

j or i == 0, continuing

J is 4

I is 0

j or i == 0, continuing

j == 5, breaking


J is 0

I is 1

j or i == 0, continuing

J is 3

I is 1

3

j == 5, breaking


J is 0

I is 2

j or i == 0, continuing

J is 3

I is 2

6

j == 5, breaking


J is 0

I is 3


j or i == 0, continuing

J is 1

I is 3

3

J is 2

I is 3

6

J is 3

I is 3

9

J is 4

I is 3

12

j == 5, breaking
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:47:20+00:00Added an answer on June 3, 2026 at 9:47 am

    The 3 (and later on, the 6), is occurring from this piece of code…

            if (!((j*i % 3) != 0)) {
                System.out.println("J is " + j);
                System.out.println("I is " + i);
                System.out.println(j*i);
            }
    

    Effectively what !((j*i % 3) != 0) is saying is, when j*i/3 has a remainder of 0, it runs the code within this if statement. In other words, it runs this if code whenever j*i is a multiple of 3 (3, 6, 9, 12)

    The logic is hard to follow – it’d be better to write it like this…

            if ((j*i % 3) == 0) {
                System.out.println("J is " + j);
                System.out.println("I is " + i);
                System.out.println(j*i);
            }
    

    In the original way, all the ! symbols and multiple brackets/braces make it hard to read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to generate an output similar to this: 1. One 2. Two 3.
I'm trying come up with the best method of synchronizing particular rows of 2
I’m looking for a portable method for creating threads specifically for output of data
I am starting to learn about makefiles. Looking at the output I see a
We are looking to sum the output of an expression meaning that it does
I am looking for a way to output an instantiated class, an Object to
Looking for an awk (or sed) one-liner to remove lines from the output if
I am looking for a way to have output in the same manner as
I'm looking for a way to send the output of an arbitrary Emacs command
I'm looking for some LaTeX template for creating quality output. On R-bloggers I've bumped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.