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 8784049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:59:17+00:00 2026-06-13T20:59:17+00:00

I need to use a nested for loop to get a list of prime

  • 0

I need to use a nested for loop to get a list of prime numbers, here is the code:

public static void main(String[] args) {

        for (int i = 2; i <= 10; i++)
        {
            for (int d = 3; d <= 10; d = d + 2)
            {
                 int result = d % i;
                 System.out.println(result);

            }
        }
    }

I think I have the logic right here, but the results was a bit out of mind, any suggestions please ?

  • 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-13T20:59:19+00:00Added an answer on June 13, 2026 at 8:59 pm

    What you are doing is only a bit related to finding out prime numbers in that, you are using modulus operator, that is needed, but nothing more than that.

    You actually need to make use of the result of that operation.

    You can follow the following pseudo-code: –

    for i = 2 to 10 {
    
        1. set a boolean flag for prime to false;
    
        2. for j = 2 to (i - 1) {  // Since we just need to check modulus till that number
            1. check the result of `i % j`
            2. If any of the result in this loop is `0`, then `i` is not a prime number. 
               So, set the `prime` flag to false, and break out of loop, 
        }
        3. check the value of `prime` flag. If it is `true`, print number is `prime`. 
           Else print not prime 
    }
    

    I am not giving away the code, since it would be beneficial for you to try it out on your own. You will learn how to implement a problem statement given in the form of algorithmic steps.

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

Sidebar

Related Questions

If I have code with nested objects like this do I need to use
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
I am trying to accomplish a module where i need to use nested templates
I need use this code: <%= button_tag :class => btn btn-primary do %> <%=
I've written some code that includes a nested loop where the inner loop is
I've got a nested foreach loop that I really need to cut the computation
I have a nested list, and I need to reverse every element in the
I have installed Matlab r2010a on my computer I need use the function xlsread
So, I need use this event so I can navigate trought blog posts. I
Need to use own imaged markers instead built-in pins. I have several questions. 1.

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.