Question:
Write a program to find the numerological value for a given name.
Note: Store the numerological number and the corresponding character in a 2-D array(2*26). Always the given name should be in a capital case,else the name is not valid. Check for the valid name, if the name is invalid print the message “Invalid name”.There should not be any space in the name provided.
For example:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
1 2 3 4 5 8 3 5 1 1 2 3 4 5 7 8 1 2 3 4 6 6 6 5 1 7
Sample Input 1:
Enter your name:
SUDHA
Sample Output 1:
Your numerology no is:19
Sample Input 2:
Enter your name:
kiran
Sample Output 2:
Invalid name
Sample Input 3:
Enter your name:
ANI34
Sample Output 3:
Invalid name
Code:
Numerology.java
import java.util.*; public class Numerology { char[][] num_val={{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}, {1, 2, 3, 4, 5, 8, 3, 5, 1, 1, 2, 3, 4, 5, 7, 8, 1, 2, 3, 4, 6, 6, 6, 5, 1, 7}}; public char numerological_value(char chr) { for(int i=0;i<26;i++) { if(chr==(num_val[0][i])) { return num_val[1][i]; } } return 0; } public static void main (String[] args) { Scanner sc=new Scanner(System.in); Numerology obj=new Numerology(); System.out.println("Enter your name:"); String name=sc.nextLine(); int len=name.length(); int flag=0, val=0; for(int i=0; i<len;i++) { char r=name.charAt(i); int temp=(obj.numerological_value(r)); if(temp==0) { System.out.println("Invalid name"); flag++; break; } else { val+=(int)temp; } } if(flag==0) { System.out.println("Your numerology no is:"+val); } } }
Recommended:
- Array square
- Generate number using odd digits
- Alternate Number Difference
- Next Greatest number
- Mark Comparison
- Print the characters in descending order
- Vowels in a fishBowl
- Least offer
- Ascending and descending order
- Mail Domain
- Count repeating words
- Sentence – Convert to upper and lower
- Count consecutive repeating characters
- Zig zag Array
- Pass and Fail Count
- Search a Course
- Average and Grade Calculation
- String – Find and replace the character (first occurrence)
- Sort the first and second half of an array
- Retail Shop
- Palindrome
- Numerology
- InitCap
- Array Compatiblilty
- Sum of the maximum and the minimum element
- String Concatenation
- Find Average Age
- Login