![](https://static.wixstatic.com/media/0f65e1_657e2c52844149018ce1b2fcd9949e9e~mv2.png/v1/fill/w_75,h_42,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/0f65e1_657e2c52844149018ce1b2fcd9949e9e~mv2.png)
Code:
public class DisplayOddNumbersExample1
{
public static void main(String args[])
{
int number=50;
System.out.print("List of odd numbers from 1 to "+number+": ");
for (int i=1; i<=number; i++)
{
//logic to check if the number is odd or not
//if i%2 is not equal to zero, the number is odd
if (i%2!=0)
{
System.out.print(i + " ");
}
}
}
}
Output:
![](https://static.wixstatic.com/media/0f65e1_f84aaa85d9044c58ab7f7fc4908d1c75~mv2.png/v1/fill/w_46,h_4,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/0f65e1_f84aaa85d9044c58ab7f7fc4908d1c75~mv2.png)
Resource: Javapoint
The Tech Platform