• Register
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?

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

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.

13 9 6
94,260 points

Related questions

0 votes
1 answer 16 views
16 views
Problem: What am I suppose to do with this issue? >Given two integers l and r print all the odd numbers between.
asked 6 days ago Ashok Dileep 5.3k points
0 votes
1 answer 27 views
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.
asked May 2 anika11 32.2k points
0 votes
1 answer 87 views
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.
asked Apr 25 Supti 13k points
0 votes
1 answer 7 views
7 views
Problem: Please help me &hellip; how can I solve it? Number of odd numbers between two numbers
asked Apr 4 Ifra 37.2k points
0 votes
1 answer 11 views
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?
asked May 1 ochena 23.3k points
0 votes
1 answer 3 views
3 views
Problem: Is there any way for me to find the number of multiples between two numbers ?
asked 2 days ago Isac Christiaan 9.6k points
0 votes
1 answer 5 views
5 views
Problem: I need assistance with a Java program that prints even and odd numbers?
asked Apr 17 jamuna1 30.2k points
0 votes
1 answer 9 views
9 views
Can anybody tell me how to print even and odd numbers using threads in java?
asked Mar 30 Madhav96 2.3k points
1 vote
1 answer 7 views
7 views
Problem: Can anyone tell me the solution of this problem? java random number between two numbers
asked Mar 26 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 2 views
2 views
Problem: Is there a workaround for this > When the loop terminates , result should hold the product of the odd numbers between 10 and 20.
asked Apr 23 ummeshani 10.8k points