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: Need help fixing the While Loop to stop printing "END", I don't know where I am going wrong, Please help!

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Need help fixing the While Loop to stop printing "END", I don't know where I am going wrong, Please help!

    Data input is get.String and get.Int. Everything works except for at the end it prints "END" which is the condition "if sn is END" then the while loop should stop, but I can not get it to stop printing END after it has stopped. I am a Beginner Student Programmer. Thanks in advance.

    Example Data input:
    A N Other
    100
    B N Other
    40
    C N Other
    39
    D N Other
    20
    END

    Expected Results:
    A N Other Pass
    B N Other Pass
    C N Other Fail
    D N Other Fail

    Actual Results:
    A N Other Pass
    B N Other Pass
    C N Other Fail
    D N Other Fail
    END Fail


    public class Main
    {

    public static void main( String args[] )
    {

    String sn = BIO.getString();
    String en = "END";


    while ( sn != en )
    {


    int cw = BIO.getInt();

    if (cw >= 40)
    {

    System.out.printf(sn + " Pass ");

    sn = BIO.getString();

    }

    else if (cw <= 39)
    {

    System.out.printf(sn + " Fail ");

    sn = BIO.getString();

    }

    }
    }

    }

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Need help fixing the While Loop to stop printing "END", I don't know where I am going wrong, Please help!

    What is BIO?
    Whatever you are, be a good one

Similar Threads

  1. Replies: 2
    Last Post: May 22nd, 2014, 01:17 PM
  2. How can I add empty string ("") to the end of textfile
    By lordofrandom in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 17th, 2013, 05:05 PM
  3. "Ask a Question" menu item dumps into "What's Wrong With My Code?"
    By GregBrannon in forum Forum Updates & Feedback
    Replies: 1
    Last Post: August 6th, 2013, 03:37 AM
  4. Polygon "Fixing" Algorithm
    By Xkynar in forum Java Theory & Questions
    Replies: 1
    Last Post: April 18th, 2013, 11:37 AM
  5. Trying to get an "if" statement to work in a "for loop".
    By JAKATAK in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 1st, 2013, 11:16 PM

Tags for this Thread