Wednesday, August 17, 2005

A Simple Java Code



import java.util.Vector;

public class MyCodons{

//globals
Vector codons = new Vector();
String[] bases = {"a","g","c","t"};

//fill the 'codons' vector with values
public MyCodons(){
for(int x=0; x<bases.length; x++){
for(int y=0; y<bases.length; y++){
for(int z=0; z<bases.length; z++){
codons.add(bases[x]+bases[y]+bases[z]);
}
}
}
}

//display the 64 codons
public void printCodons(){
System.out.println(codons.size()+" possible codons\n"+ codons);
}

//main method
public static void main(String[] args){
System.out.println("Generating codons...\n");
MyCodons obj = new MyCodons();
obj.printCodons();
}
}

No comments: