Saturday, 11 July 2009

Is this how to convert Strings to numbers and search them?? Is there a simpler way??

/**This program takes the name of a comet and a group ( BOTH IN
CAPITAL LETTER ) and tells whether that group will be abducted by
aliens or not*/

import java.io.*;
import java.util.*;

public class Your_Ride_Is_Here {
public static void main (String args[]) {
Scanner input = new Scanner(System.in);
System.out.println ("Enter Comet Name: ");
String cometname = input.nextLine();
char [] notreference =
{'1','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','2'};
char [] cometarray = new char [cometname.length()];
cometname.getChars(0,cometname.length(), cometarray,0);
System.out.println ("Enter Group Name: ");
String groupname = input.nextLine();
char [] grouparray = new char [groupname.length()];
groupname.getChars(0,groupname.length(), grouparray,0);
int product1=1;
int product2=1;
char [] reference = {'
','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'};
for(int countcomet=0; countcomet while( countcomet int count1 = 0;
while (count1<=26) {
if (cometarray[countcomet]==reference[count1]) {
product1= product1*count1;
}
count1++;
}
countcomet++;
}
}
for(int countgroup=0; countgroup{
while( countgroup int count2 = 0;
while (count2<=26) {
if (grouparray[countgroup]==reference[count2]) {
product2= product2*count2;
}
count2++;
}
countgroup++;
}
}
if (product1%47 == product2%47) {
System.out.println ("YES");
}
else {System.out.println ("NO");
}
}
}

No comments:

Post a Comment