Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Loops with boolean variables!

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Loops with boolean variables!

    I'm writing a complex for loop to find prime numbers. What I have so far is this:

    public static void algorithmOne(int n) {

    boolean isPrime = true; //the number is a prime (has remainder)


    for(int m = 2; m < n; m++) {

    for (int c = 2; c < m; c++){
    if(m%c == 0) isPrime = false; //is not a prime

    }
    What I guess I'm trying to achieve is the rest of the loop...but I don't know how
    I'm going to have to continue the loop somehow, end it, and print out the prime numbers.

    Help please!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Loops with boolean variables!

    the rest of the loop
    What are the steps that the loop needs to do? You need to research the algorithm for finding prime numbers.

    Use code tags, not quote tags, to format the code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    java-noobette (April 8th, 2013)

Similar Threads

  1. What does '^' do? Is this a boolean?
    By ColeTrain in forum Java Theory & Questions
    Replies: 2
    Last Post: October 19th, 2012, 02:58 PM
  2. Differences between local variables and instance variables
    By rob17 in forum Java Theory & Questions
    Replies: 2
    Last Post: March 6th, 2012, 08:34 PM
  3. Instance Variables and local variables difference
    By dcwang3 in forum Java Theory & Questions
    Replies: 3
    Last Post: October 31st, 2011, 06:33 AM
  4. [SOLVED] Boolean Flag Not Working to Move Between While Loops?
    By verbicidalmaniac in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 8th, 2011, 09:04 PM
  5. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM

Tags for this Thread