Find odd numbers between two numbers java

1 vote
36 views

Problem:

Hello guys,

I am a novice in Java programming. I have started learning the java programming out of curiosity and I am loving it. I am solving primitive problems from a website. I recently got a question that says to find odd numbers between two numbers java. Let’s say I’ve to find out all the odd numbers between 1 – 50. Yeah, I know what is an odd number and how to identify them. Finding odd numbers in a range is totally new to me.
Could any of you please show me a way?

1 vote

Solution:

Finding odd numbers between a range is not something out of the world! All you just need to run an iteration over the range and pick up the odd numbers once you get. That's it!

``````public class OddNumbers{
public static void main(String args[]){
System.out.println("The Odd Numbers Between 0-50's are:");
for (int n = 1; n <= 50; n++){
if (n % 2 != 0){
System.out.print(n + " ");
}
}
}
}``````

Run the program. It should print all the odd numbers in that range. Thanks.

Related questions

16 views
Problem: What am I suppose to do with this issue? >Given two integers l and r print all the odd numbers between.
27 views
Problem: I am doing a code challenge where given two integers l and r, I have to print all the odd numbers between i and r (i and r inclusive). The function must return an array of integers denoting the odd numbers between l and r. This is what I have ... Wrong Answer Your Output (stdout) Output hidden Any ideas for this? on the QA of the challenge site, it seems related to Corner case problems.
87 views
Problem: I am doing a code challenge where given two integers l and r, I have to print all the odd numbers between i and r (i and r inclusive). The function must return an array of integers denoting the odd numbers between l and r. This is what I have ... Wrong Answer Your Output (stdout) Output hidden Any ideas for this? on the QA of the challenge site, it seems related to Corner case problems.
7 views
Problem: Please help me &hellip; how can I solve it? Number of odd numbers between two numbers
11 views
Problem: I am trying to calculate the sum of the odd numbers between two user inputted numbers. This is the code I have so far: import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("# 1: ") ... . However, with 4 and 20, it outputs 108, which is not correct. It should instead be 96. Where have I gone wrong in the code?
3 views
Problem: Is there any way for me to find the number of multiples between two numbers ?
5 views
Problem: I need assistance with a Java program that prints even and odd numbers?