top of page
Writer's pictureThe Tech Platform

Write a program to print Odd Numbers from 1 to 50.



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:



Resource: Javapoint


The Tech Platform

0 comments

Comments


bottom of page