import groovy.io.*;
class AlphabetToDigit {
Scanner scan=new Scanner(System.in);
def txt;
def ch;
def str="";
def input(){
try{
printf "Enter A Word: ";
txt=scan.nextLine();
compute(txt);
} catch(e){
System.err.println "Error Occurred!\n$e"+e.getMessage();
System.exit(0);
}
}
def compute(txt){
for(def i in 0..txt.length()-1){
ch=txt.toUpperCase().charAt(i);
switch(ch){
case 'A': str+="01"; break;
case 'B': str+="02"; break;
case 'C': str+="03"; break;
case 'D': str+="04"; break;
case 'E': str+="05"; break;
case 'F': str+="06"; break;
case 'G': str+="07"; break;
case 'H': str+="08"; break;
case 'I': str+="09"; break;
case 'J': str+="10"; break;
case 'K': str+="11"; break;
case 'L': str+="12"; break;
case 'M': str+="13"; break;
case 'N': str+="14"; break;
case 'O': str+="15"; break;
case 'P': str+="16"; break;
case 'Q': str+="17"; break;
case 'R': str+="18"; break;
case 'S': str+="19"; break;
case 'T': str+="20"; break;
case 'U': str+="21"; break;
case 'V': str+="22"; break;
case 'W': str+="23"; break;
case 'X': str+="24"; break;
case 'Y': str+="25"; break;
case 'Z': str+="26"; break;
case ' ': str+=" "; break;
default: str+=ch;
}
}
}
def display(){
println "Digits: $str";
}
def String getDigit(str){
compute(str);
return this.str;
}
public static void main(args){
AlphabetToDigit alf=new AlphabetToDigit();
alf.input();
alf.display();
}
}
class AlphabetToDigit {
Scanner scan=new Scanner(System.in);
def txt;
def ch;
def str="";
def input(){
try{
printf "Enter A Word: ";
txt=scan.nextLine();
compute(txt);
} catch(e){
System.err.println "Error Occurred!\n$e"+e.getMessage();
System.exit(0);
}
}
def compute(txt){
for(def i in 0..txt.length()-1){
ch=txt.toUpperCase().charAt(i);
switch(ch){
case 'A': str+="01"; break;
case 'B': str+="02"; break;
case 'C': str+="03"; break;
case 'D': str+="04"; break;
case 'E': str+="05"; break;
case 'F': str+="06"; break;
case 'G': str+="07"; break;
case 'H': str+="08"; break;
case 'I': str+="09"; break;
case 'J': str+="10"; break;
case 'K': str+="11"; break;
case 'L': str+="12"; break;
case 'M': str+="13"; break;
case 'N': str+="14"; break;
case 'O': str+="15"; break;
case 'P': str+="16"; break;
case 'Q': str+="17"; break;
case 'R': str+="18"; break;
case 'S': str+="19"; break;
case 'T': str+="20"; break;
case 'U': str+="21"; break;
case 'V': str+="22"; break;
case 'W': str+="23"; break;
case 'X': str+="24"; break;
case 'Y': str+="25"; break;
case 'Z': str+="26"; break;
case ' ': str+=" "; break;
default: str+=ch;
}
}
}
def display(){
println "Digits: $str";
}
def String getDigit(str){
compute(str);
return this.str;
}
public static void main(args){
AlphabetToDigit alf=new AlphabetToDigit();
alf.input();
alf.display();
}
}
Comments