• Register
1 vote
19 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,240 points

Related questions

0 votes
1 answer 38 views
38 views
Problem: Hello Kodlogs, I am preparing for campus recruitment.I am going through most popular interview questions in java.However ,i am unable put the GCD of two number progrmatically.Could any one help me this?
asked Oct 8, 2020 kalyani456 280 points
0 votes
1 answer 10 views
10 views
Problem: Can anyone tell me what's wrong with the code?
asked Feb 17 TeamScript 13.5k points
0 votes
1 answer 32 views
0 votes
1 answer 5 views
5 views
Problem: i am a begginer and i want to explain to me that with code please
asked Feb 9 ahmedadel9090 2.6k points
0 votes
1 answer 15 views
15 views
Write a program in Java to add two binary numbers?
asked Oct 11, 2020 sikandar 2.4k points
0 votes
1 answer 27 views
27 views
Problem: i have seen a program using a while-statement to solve this problem. Here, we will see that this problem can be solved more naturally using a for-statement. Problem description: Write a Java program that reads in an integer n... and prints all its divisors
asked Nov 4, 2020 Mashhoodch 9.1k points
0 votes
1 answer 14 views
14 views
Problem: Hi everyone. I am badly struggling in finding shortest or smallest path b/w two nodes. Please suggest me any solution.
asked Nov 5, 2020 Mubashi-Question 1.7k points
0 votes
1 answer 31 views
31 views
Problem: I have two ArrayList objects with three integers each. I want to find a way to return the common elements of the two lists Use Collection#retainAll(). listA.retainAll(listB); // listA now contains only the elements which are also contained in listB.
asked Nov 6, 2020 Mashhoodch 9.1k points
0 votes
1 answer 43 views
43 views
Problem I know it is easy. But I need it. Provide me the code to find the greatest common divisors (GCD) which is also called HCF. answer me in an easy-to-understand manner.
asked Dec 2, 2020 chris jordan 2.4k points
0 votes
1 answer 176 views
176 views
I understand the questions but the thing that im not sure about is the part it says "using functions". here is my code and wonder if its acceptable; x= int(input("Enter first number:")) y= int(input("Enter second number:")) sum=x+y average=sum/2 print("Sum of the given two numbers is:", sum) print("Average of the given numbers is:", average)
asked Oct 28, 2020 psandprop 2.4k points