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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:43:28+00:00 2026-06-13T05:43:28+00:00

public static long sum7() { int c = 1; boolean isprime = true; long

  • 0
public static long sum7()
{
    int c = 1;
    boolean isprime = true;
    long prime = 0;
    for (long i = 3; i <= Long.MAX_VALUE; i++)
    {
        for (long j = 2; j < i; j++)
        {
            if (i % j == 0)
            {
                isprime = false;
                break;
            }
        }
        if (isprime == true)
        {
            c++;
        }
        if (c == 10001)
        {
            prime = i;
            break;
        }
    }
    return prime;
}
static Scanner scanner1 = new Scanner(System.in);

public static void main(String[] args)
{
    System.out.println(sum7());
}

I was trying out the following code for a project euler question(Q7), i’m supposed to locate the 10001st prime number but it was just not working. The build is successful but it is not showing anything Please help. Thanks in advance….

  • 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-13T05:43:29+00:00Added an answer on June 13, 2026 at 5:43 am

    It’s not clear exactly what you’re trying to do, so I have to guess based on the code. I’m assuming that you wish to find the 10001th prime number.

    First off, you forgot to set isprime back to true at the end of the loop. As it is now, it will permanently be false after the first iteration, meaning that 3 is the only prime detected and you’ll loop all the way up to 2^63 (effectively infinite) after that and eventually return 0.

    You can solve the problem and also scope your variable better by moving boolean isprime = true; to the start of the loop. You might as well move prime into the loop while you’re at it and change the if c==10001 bit to just return directly.

    Secondly, c = c++; isn’t correct. You’re incrementing the variable and then resetting it to the old value. You should either do c++; or c = c + 1.

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

Sidebar

Related Questions

public class StoreMessage extends Thread implements Serializable{ private static long start_nanotime=System.nanoTime(); private static int
I have two methods: power and factorial: public static long pow(int x, int n)
this is the implecation of rotateLeft in Long: public static long rotateLeft(long i, int
I have solved the following algorithm shown below. public static long park(int n) {
public class Knowing { static final long tooth = 343L; static long doIT(long tooth)
import org.joda.time.LocalDate; public class Test { public static void main(String[] args) { long time=System.currentTimeMillis();
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
Given the following code: public class A { static final long tooth = 1L;
Here's an example of a utility method: public static Long getFileSize(String fileString) { File
I found one method in Long class public static long reverse(long i) {..} What

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.