Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Thursday, 7 July 2011

Write a program that print all odd numbers from 0 to a user specific number using do while loop

import java.util.*;
class odd
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);

int a;
System.out.print ("\n\t Enter the ending number = ");
a=in.nextInt();

do
{
if (a%2!=0)
System.out.print ("\n\t "+a);
--a;
}while (a>0);

}
}

Note:
     In this program if we divide a by 2 and it do not returns 0, then it will be printed on
screen otherwise not.

No comments:

Post a Comment