How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask lifesaver Your Own Question
lifesaver
lifesaver, Computer Software Engineer
Category: Programming
Satisfied Customers: 5962
Experience:  Several years of intensive programming and application development experience in various platforms.
16528259
Type Your Programming Question Here...
lifesaver is online now
A new question is answered every 9 seconds

Write a java program to list all odd numbers between two n

This answer was rated:

Write a java program to list all odd numbers between two numbers
Hi,
Here is your code:-

import java.io.*;

class AllOddNum{
public static void main(String[] args) {
try{
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number : ");
int num = Integer.parseInt(br1.readLine());
System.out.println("odd Numbers:");
for (int i=1;i <=num ; i++){
if(i%2!=0 ){
System.out.print(i+",");
}
}
}
catch(Exception e){}

}
}


If you find my answer useful, please press the Accept button and give me a positive feedback (and I will give a positive feedback). Bonuses are appreciated. If you need any further help just contact me!!

lifesaver and 4 other Programming Specialists are ready to help you
Customer: replied 8 years ago.
i saw a similar answer to this so im a bit dissapointed. im supppsed to use the different loops for this code so im back at square one.
I am sorry if i disappointed you.I assumed that you could other different loops pf your own.Its simple.

Just add the code for do while loop:

int i=1;
do{
if(i%2!=0 )
{
System.out.print(i+",");
}
i++;
}while(i<=num)

For a while loop:-
int 1=1;
while(i<=num){
if(i%2!=0 )
{
System.out.print(i+",");
}
i++;
}

Related Programming Questions