473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

displaying odds only

hi, im having trouble with a java program. i need to know how to display only the odd numbers using a simple while loop.

the user has to enter a number greater than or equal to 1

for example, i prompt the user to enter a number.

if the number the user enters is '6' , i want to display 1, 3, and 5 (all the odds before i get to the value the user got in)

if the number the user enters is '13', i want to display 1, 3, 5, 7, 9, 11, and 13.

can anyone help me with this?
Feb 8 '07 #1
2 1247
try this friend,

public class oddNumberDisplay
{
public static void main(String[] args)
{
int num = 10; /* enter the number here */
for(int i=1;i<=num;i++)
{
if((i%2)!=0)
{
System.out.println(i);
}
}
}
}
Feb 8 '07 #2
rengaraj
168 100+
did u got the answer ???
Feb 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
1
by: siva prasad | last post by:
hello, i have an appplication in which when i click a button then all the odds in a website are to be displayed. so i need Regular Expressions for identifing the odds.i am in the learner stage of...
1
by: Mamatha | last post by:
Hi I want to write regular expression for odds which related to sports in VB.NET. But i don't know how to write regular expression for odds. If anyone knows the solution or any related urls...
4
by: Jason Chan | last post by:
How can I get the month and year a calendar control current displaying? My problem is I want to load a list of event to a calendar so that it display difference style if there a event for a day....
4
by: hardieca | last post by:
Has anyone heard of an open-source .NET engine that calculates the winning and losing percentages of hands? Regards, Chris
8
by: highroller152 | last post by:
Not to step on anyone, but in reference to this thread on summing odds and evens, why not just use the 'continue' statement? So adding up the odds would look something like this: -on some event-...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.