Search code examples
javaloopsbluej

I was making a program to display odd numbers from 1 to 100 using loops


I am a begineer in java programming. I was making a program to display odd numbers from 1 to 100 using loops. But that program when executed displays the odd number from 7 to 100 please help me to rectify that program. The program.....

public class oddnumbers1to100
{
    public static void main(String args[])
    {
        for(int a=1;a<=100;a+=2) {
            System.out.println(a);
        }
    }
}

Solution

  • As expected the issue is the console you're using, in fact the console integrated in BlueJ, your IDE.

    You can do two things to get the full output:

    • List numbers horizontally:

      for (int a = 1; a <= 100; a+=2)
          System.out.print(a + " ");
      
    • Or change the buffer setting of your console:

      • Click on "View" and then "Show Terminal" in the main menu (shortcut Ctrl + T)
      • Then click on "Options" and select "Unlimited buffering"

    Uninstalling the compiler or the IDE (as suggested in the comments) won't help you here, since it is not a problem of your program or your compiler.