Numerology number Program in java

Question:

Harry has developed a new interest in learning numerology, so starts paying attention to the numbers that comes up as he goes about his daily routines.

Write a program to help him. The program should get the input from the user and display the individual digits separated by a single space. Assume input is less than 1000000000. For example, the number 7654 should be displayed as 7 6 5 4

Also display the sum of the digits, the numerology number(Multi-digit numbers are added and reduced to a single digit), number total number of odd numbers and total number of even numbers.

For example if the given number is 7654 then,

The Numbers are :    7    6    5    4   

Sum of digits : 22 (7+6+5+4)

Numerology number : 4 ((7+6+5+4 =22 => 2+2) sum of digits is again added and reduced to a single digit).

Number of odd numbers: 2

Number of even numbers: 2

Sample input:

Enter the number

86347

Sample output:

The Numbers are :    8    6    3    4    7

Sum of digits : 28

Numerology number: 1

Number of odd numbers: 2

Number of even numbers: 3

CODE:

import java.util.Scanner;
public class Main 
{
    public static void main (String[] args)
    {
        String str_num="";
        int sum=0, even_numbers=0, odd_numbers=0, numerology_number=0, r=0;
        Scanner sc= new Scanner(System.in);
        System.out.println("Enter the number");
        int num=sc.nextInt();
        int temp=num;
        
        while(temp>0)
        {
            r=temp%10;
            str_num=(char)(r+'0')+" "+str_num; //(char)(r+'0') makes the int printable.
            sum+=r;
            if(r%2==0)
            {
                even_numbers++;
            }
            else
            {
                odd_numbers++;
            }
            temp/=10;
        }
        numerology_number=sum;
        Main obj=new Main();
        while(numerology_number>9)
        {
            numerology_number=obj.numer(numerology_number);
        }
        
       
        
        System.out.println("The Numbers are : "+str_num);
        System.out.println("Sum of digits : "+sum);
        System.out.println("Numerology number: "+numerology_number);
        System.out.println("Number of odd numbers: "+odd_numbers);
        System.out.println("Number of even numbers: "+even_numbers);
    
    }
    
    int numer(int a)
    {   
        int ans=0, temp=a, r=0;
        while(temp>0)
        {
            r=temp%10;
            ans+=r;
            temp/=10;
        }
        return ans;
    }
}

Leave a Comment

Scroll to Top