How can I iterate over a string in Java?

前端 未结 9 1677
余生分开走
余生分开走 2021-01-02 12:40
public static Boolean cmprStr( String s1, String s2 )
{
    // STUFF
}

I want to iterate through s1 to make sure that every character in s1 is incl

9条回答
  •  一生所求
    2021-01-02 13:28

    // Here's some code I wrote to find CG ratio in a gene     
    public double findCgRatio(String gene)
            {
                double cCount =0.0; 
                double gCount =0.0; 
                gene = gene.toLowerCase(); 
                for(char character : gene.toCharArray())
                {
                    if(character == 'c')
                    {
                        cCount++; 
                    }
                    else if(character == 'g')
                    {
                        gCount++; 
                    }
    
                }
                System.out.println("CG Ratio was :" + (cCount/gCount) );  
                return cCount/gCount;  // cgRatio 
            }
    

提交回复
热议问题