Challenge:
Given the following information:
a = 26, b = 25, c = 24, d = 23 ..... x = 3, y = 2, z = 1
a = 26, b = 25, c = 24, d = 23 ..... x = 3, y = 2, z = 1
What is the sum of each letter of this sentence: "The quick brown fox jumped over the cow"?
Answer:
public class Revalphabetcodes {
public static void main(String[] args) {
String element="The quick brown fox jumped over the cow";
int cycle=element.length()-1;
int sum=0;
while(cycle>-1){
if(Character.getNumericValue(element.charAt(cycle))!=-1){
sum+=36-Character.getNumericValue(element.charAt(cycle));
}
cycle--;
}
System.out.println("sum is: "+sum);
}
}
No comments:
Post a Comment