Moran Numbers in Java10 Sept 2024 | 6 min read In this tutorial, we will be discussing Moran numbers in Java. A moran number is a number, when divided by the sum of its digits, generates a prime number. Note that the sum of the digits of the number should be the factor of that number. Let's understand with the help of a few examples. Example 1:Input: 45 Output: 45 is a Moran number. Explanation: The sum of the digits of the number 45 is 4 + 5 = 9, and when 45 is divided by 9, we get 45 / 9 = 5, and 5 is a prime number. Hence, 45 is a Moran number. Example 2:Input: 36 Output: 36 is not a Moran number. Explanation: The sum of the digits of the number 36 is 3 + 6 = 9, and when 36 is divided by 9, we get 36 / 9 = 4, and 4 is not a prime number. Hence, 36 is not a Moran number. Example 3:Input: 22 Output: 22 is not a Moran number. Explanation: The sum of the digits of the number 22 is 2 + 2 = 4, and 4 is not the factor of the number 22. Hence, 22 is not a Moran number. Validation For the Moran NumberObserve the following algorithm. Step 1: Take a number n. Step 2: Compute the sum of the digits of the number n. Step 3: Check whether the sum of the digits is the factor of the number n or not.
ImplementationObserve the implementation of the above algorithm. FileName: MoranNum.java Output: The number 45 is a Moran number. The number 36 is not a Moran number. The number 22 is not a Moran number. Finding Moran Numbers Within A RangeIn this approach, we will be using a sieve to find the moran numbers within the given range. We are using the sieve because we do not want to use a loop for doing the validation for a prime number. The rest of the other stuff remains the same as the above-written approach. Observe the program. FileName: MoranNum1.java Output: The Moran numbers that lie within the range 1 to 200 are: 18 21 27 42 45 63 84 111 114 117 133 152 153 156 171 190 195 198 |
NumberFormatException
in Java The is thrown when we try to convert a string into a numeric value such as float or integer, but the format of the input string is not appropriate or illegal. By illegal format, it is meant that if you are trying to...
3 min read
Eclipse Change Theme
Eclipse is one of the most used and popular IDE among developers. It has out of box features and functions that stand it out from other IDEs. There are various factors that influence our ability to code effectively and efficiently. From AI-driven code completion assistance to...
2 min read
Difference Between for loop and for-each Loop in Java
Difference Between for Loop and for-each Loop in Java A loop is simply a way to repeat a specific block of code multiple times as long as a certain condition remains true. Programming languages usually offer different kinds of loops to handle repetition, such as while,...
6 min read
Object in Java
Java is an object-oriented programming language, which means that objects play a central role in its design. Fundamental things in Java that contain data and behaviours are called objects. For Java code to be efficient and modular, understanding objects is crucial. We will examine objects...
4 min read
Image Processing in Java- Face Detection
One of the most important applications of computer vision is face detection which is applied in many fields like security systems, identification systems as well as image processing systems. Although there is numerous Java face detection software available, one which is worth mentioning is OpenCV, an...
4 min read
XOR and XNOR operators in Java
One of the Bitwise operators offered by Java is XOR. Two boolean operands are given to the XOR (also known as exclusive OR), which returns true if they are different. When neither of the two boolean conditions supplied can be true simultaneously, the XOR operator is...
7 min read
How to find trigonometric values of an angle in Java
? Trigonometry plays a crucial role in mathematics and various scientific applications, including computer graphics, physics, engineering, and more. In Java, we can easily find the trigonometric values of an angle using built-in math functions provided by the java.lang.Math class. In this section, we will discuss the...
4 min read
Decimalstyle withNegativesign() Method in Java with Example
The java.time.format.DecimalStyle class contains withNegativeSign() function. The character that is used to represent the negative sign for this DecimalStyle's locale in Java is set using the DecimalStyle class. Upon obtaining the character as an input, this function produces a DecimalStyle object containing the revised negative sign...
3 min read
How to Implement a Simple Network Monitoring Tool in Java?
In Java, administrators and users require network monitoring tools to perform basic operations on networked systems. A network monitoring tool helps in monitoring and analysing network traffic, assuring optimal performance and security. To create a simple network monitoring tool in Java, use built-in libraries like java.net for...
3 min read
Java Swing Interview Questions and Answers
Java Swing exists as a segment of Java Foundation Classes (JFC), which delivers a comprehensive set of GUI elements to construct Java desktop applications. Swing offers improved visual features in addition to being lightweight and independent from platform restrictions when compared to AWT (Abstract Window Toolkit). The...
5 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India