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: even numbers code not working

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default even numbers code not working

    Hi! I have tried for two hours to fix why this code is not doing anything and I gave up. Please help! the idea is to write a program that prints out the even numbers from 0 to 500 (including the number 500) using a while loop.

    public class EvensWhile extends ConsoleProgram
    {
    public static void main(String[] args)
    // Prints out the even numbers from 0 .. 500

    {
    int i = 0;
    while (i <= 500)
    {
    System.out.println(i * 2);
    i++;
    }
    }
    }

  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: even numbers code not working

    this code is not doing anything
    Please explain what happens when the code is compiled and executed.

    What is the purpose of extending the ConsoleProgram class? What happens when the extends is removed?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. want to modify code that converts binary code to decimal numbers
    By noblegas in forum What's Wrong With My Code?
    Replies: 12
    Last Post: August 29th, 2014, 05:30 PM
  2. working with decimal point numbers
    By raam in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 9th, 2013, 07:29 AM
  3. java -working with decimal numbers
    By raam in forum Member Introductions
    Replies: 2
    Last Post: December 9th, 2013, 05:44 AM
  4. Replies: 7
    Last Post: April 25th, 2013, 01:12 PM
  5. IF statement accumulataion not working properly - random numbers
    By StrugglerWithJava in forum Loops & Control Statements
    Replies: 1
    Last Post: April 4th, 2013, 07:48 AM

Tags for this Thread