7:48 pm - Sunday September 23, 2018

Java example program to count number of odd numbers between 1 to 100

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/* Program for odd numbers*/
/**
*@author:Candidjava.com
*@Description: To check a given number is Odd
*/
public class Odd
{
	public static void main(String[] args) {
		int count = 0;
		int n;
		for (int i = 1; i <= 100; i++) {
			if (i % 2 != 0) {
				count = count + 1;
				System.out.println(i);// display the odd value
			}
		}
		System.out.println("count:" + count);// display the count value
	}
}

Output:

1
3
5
.
.
.
99

Filed in: Sample Programs in java

Comments are closed.