usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

How to Generate Odd Numbers in Java for Kids



Understanding Odd Numbers in Math with Java

Odd numbers are numbers that are not divisible by 2.

They include:

1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...

In this beginner-friendly Maths Java tutorial for kids, we’ll explore how to list odd numbers using loops and conditions — perfect for primary school students learning to code.
To generate odd numbers in Java, we use a 'while' loop combined with a conditional statement. This simple Java exercise will help you understand number patterns and logic.

Create a new class file; File, New File.
Call it OddNumbers.
Type out the adjoining Java code for listing odd numbers.



Note: You can comment out the evenNumbers Java object code in the main class from the previous lesson or simply continue from where it stopped.



Code for Odd Number List with Input in Java

For a little more flexibility, let's add an input form to our Java code for odd numbers.

All we need is a way to ask the user for input.
For this purpose, we'll import and use the System.in and Scanner Java library classes.










<< PreviousNext >>