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 3 of 3

Thread: Why is this code not printing to console

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why is this code not printing to console

    I was expecting the while loop inside the main method to print to console.
    What is happening here?

     
    class ControlFlow {
      public static void main(String[] args) {
     
     
      int number = 4;
      int finishNumber = 20;
     
      while (number <= finishNumber){
       	number++;
       	if(!isEvenNumber(number)){
           	continue;
       	}
       	System.out.println("Even number "+number);
     
      	}
      }
     
      public static boolean isEvenNumber(int num){
        return (num/2 == 0);
        }
    }
    Last edited by bertu; February 28th, 2022 at 08:04 AM. Reason: code is not highlighting despite code tag

  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: Why is this code not printing to console

    Print out the value of num/2 in the isEvenNumber method to see what values are being tested.

    Also try the modulus operator.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why is this code not printing to console

    Oh my!
    I missed the modulo!

    Thank you very much!

Similar Threads

  1. Netbeans not printing to built-in output console
    By ChristianAntfeld in forum Java IDEs
    Replies: 2
    Last Post: June 26th, 2019, 11:52 AM
  2. Not printing in console. What am i missing?
    By crgb1202 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 2nd, 2018, 10:10 AM
  3. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  4. Printing A TreeNode/Node To Console..
    By Kumarrrr in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 17th, 2010, 12:35 AM
  5. printing output to console & to a text file at the same time...
    By prasanna in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: August 26th, 2009, 03:43 AM