Numerology Name Checking

Question:

Jack is blessed with a new baby girl. He wants to celebrate the baby’s naming ceremony. He decides to choose a name for his baby based on numerology. The Logic of Numerology name is: the equivalent value of each alphabet’s (case insensitive) sum must be even and divisible by 3. Print the sum as output. If the resultant sum satisfices the above condition (Logic of numerology name), print “<Name> is Numerology name”. Else, display “<Name> is not a Numerology name.”

Here the equivalent value for alphabets are: A=1, B=2, ….., Y=25, Z=26.

Note:

The Name contains only Alphabets (Upper case or lower case). Else display “<Name> is an Invalid name”.

Sample Input 1:

Enter the Name

Rahul

Sample Output 1:

60

Rahul is a Numberology name

Explanation: R=18, a=1, h=8, u=21, l=12

18+1+8+21+12=60.

60 is an even number and also divisible by 3.

Sample Input 2:

Enter the Name

Jeeva

Sample Output 2:

43

Jeeva is not a Numerology name

Sample Input 3:

Enter the Name

Ramu@

Sample Output 3:

Ramu@ is an Invalid name

Sample Input 4:

Enter the Name

Raj2

Sample Output 4:

Raj2 is an Invalid name

Code :

Main.java

import java.util.*;
import java.util.regex.Pattern;
public class arraysquare{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter the name");
		String a=sc.next();
		if(!Pattern.matches("[A-Za-z]+",a))
		{
			System.out.println(a+" is an Invalid name");
			return;
		}
		int sum=0;
		char b[]=a.toCharArray();
		for(int i=0;i<b.length;i++)
		{
			if(b[i]=='A'||b[i]=='a')
			{
				sum+=1;
			}
			else if(b[i]=='B'||b[i]=='b')
			{
				sum+=2;
			}
			else if(b[i]=='C'||b[i]=='c')
			{
				sum+=3;
			}
			else if(b[i]=='D'||b[i]=='d')
			{
				sum+=4;
			}
			else if(b[i]=='E'||b[i]=='e')
			{
				sum+=5;
			}
			else if(b[i]=='F'||b[i]=='f')
			{
				sum+=6;
			}
			else if(b[i]=='G'||b[i]=='g')
			{
				sum+=7;
			}
			else if(b[i]=='H'||b[i]=='h')
			{
				sum+=8;
			}
			else if(b[i]=='I'||b[i]=='i')
			{
				sum+=9;
			}
			else if(b[i]=='J'||b[i]=='j')
			{
				sum+=10;
			}
			else if(b[i]=='K'||b[i]=='k')
			{
				sum+=11;
			}
			else if(b[i]=='L'||b[i]=='l')
			{
				sum+=12;
			}
			else if(b[i]=='M'||b[i]=='m')
			{
				sum+=13;
			}
			if(b[i]=='N'||b[i]=='n')
			{
				sum+=14;
			}
			if(b[i]=='O'||b[i]=='o')
			{
				sum+=15;
			}
			if(b[i]=='P'||b[i]=='p')
			{
				sum+=16;
			}
			if(b[i]=='Q'||b[i]=='q')
			{
				sum+=17;
			}
			if(b[i]=='R'||b[i]=='r')
			{
				sum+=18;
			}
			if(b[i]=='S'||b[i]=='s')
			{
				sum+=19;
			}
			if(b[i]=='T'||b[i]=='t')
			{
				sum+=20;
			}
			if(b[i]=='U'||b[i]=='u')
			{
				sum+=21;
			}
			if(b[i]=='V'||b[i]=='v')
			{
				sum+=22;
			}
			if(b[i]=='W'||b[i]=='w')
			{
				sum+=23;
			}
			if(b[i]=='X'||b[i]=='x')
			{
				sum+=24;
			}
			if(b[i]=='Y'||b[i]=='y')
			{
				sum+=25;
			}
			if(b[i]=='Z'||b[i]=='z')
			{
				sum+=26;
			}
		}
		System.out.println(sum);
		if(sum%3==0 && sum%2==0)
		{
			System.out.println(a+" is a numerology name");
		}
		else
		{
			System.out.println(a+" is not a numerology name");
		}
	}
}

OR

import java.util.*;
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the Name");
		String str = sc.nextLine();
		String str2 = str.toLowerCase();
		char[] ch = str2.toCharArray();
		int flag =0;
		int len = str.length();
		for(int i=0;i<len;i++){
			if(!(ch[i]>='a' && ch[i]<='z'))
				flag = 1;
		}
		if(flag == 1){
			System.out.println(str+" is an invalid name");
		}
		else{
			int x=0,sum=0;
			for(int i=0;i<len;i++){
				x = (int)ch[i]-96;
				sum = sum + x;
			}
			
			System.out.println(sum);
			if(sum%3 == 0){
				System.out.println(str+" is a Numerology name");
			}
			else{
				System.out.println(str+" is not a Numerology name");
			}
			
		}
	}
}

Recommended:

  1. Java Program of Fetch Mid Characters
  2. Java Program to Box Challenge
  3. Java Program to Create Login Page
  4. Java Program for Fune Mall Vehicle Parking
  5. Java program to print the characters in descending order
  6. Java Program to check Mileage Details

1 thought on “Numerology Name Checking”

  1. Pingback: OMR Evaluation - Quiz for Exam

Leave a Comment

Your email address will not be published. Required fields are marked *