当前位置: 代码迷 >> Java Web开发 >> Debug java代码
  详细解决方案

Debug java代码

热度:1107   发布时间:2008-10-03 20:44:20.0
Debug java代码
/**
* This class represents a DNA sequence of nucleotides 'A', 'T', 'C' and 'G'
* as a sequence of characters in a {@link String} object.
*
* @author  author name
* @version  1.0.0
*/
public class DNASequence  {
    private String  sequence;
    private int numberOfA;
    private int numberOfT;
    private int numberOfC;
    private int numberOfG;
    public static void  main(String[] args)  {

        String s = "ATTATCGGGGTAA";
        DNASequence dnaSequence = new DNASequence(s);

        if ((dnaSequence.getNumberOfA() == 4)
                && (dnaSequence.getNumberOfT() == 4)
                && (dnaSequence.getNumberOfC() == 1)
                && (dnaSequence.getNumberOfG() == 4)) {
            System.out.println("Test case 1:  get methods passed\n");
        } else {
            System.out.println("Test case 1:  get methods failed !!!\n");
        }

        if (dnaSequence.twoConsecutive('T')) {
            System.out.println("Test case 2: method twoConsecutive passed\n");
        } else {
            System.out.println(
                "Test case 2: method twoConsecutive failed !!!\n");
        }

        if (dnaSequence.twoConsecutive('A')) {
            System.out.println("Test case 3: method twoConsecutive passed\n");
        } else {
            System.out.println(
                "Test case 3: method twoConsecutive failed !!!\n");
        }

        if (!dnaSequence.twoConsecutive('C')) {
            System.out.println("Test case 4: method twoConsecutive passed\n");
        } else {
            System.out.println(
                "Test case 4: method twoConsecutive failed !!!\n");
        }
               
    }
    public  DNASequence(String initialSequence)  {

        sequence = initialSequence;
        countNucleotides();
    }
    private void  countNucleotides()  {
        int numberOfA = 0;
        int numberOfT = 0;
        int numberOfC = 0;
        int numberOfG = 0;
        int index = 0;
        while (index < sequence.length()) {
            char nucleotide = sequence.charAt(index);
            if (nucleotide == 'A') {
                numberOfA++;
            } else if (nucleotide == 'T') {
                numberOfT++;
            } else if (nucleotide == 'C') {
                numberOfC++;
            } else if (nucleotide == 'G') {
                numberOfC++;
            }
            index++;
        }
        return;
    }
    public int  getNumberOfA( )  {
        return numberOfA;
    }
    public int  getNumberOfT( )  {
        return numberOfT;
    }
    public int  getNumberOfC( )  {
        return numberOfC;
    }
    public int  getNumberOfG( )  {
        return numberOfG;
    }
    public boolean  twoConsecutive(char input)  {
        int index = 1;
        while (index < sequence.length() - 1) {
            int indexOfFirstNucleotide = index - 1;
            char firstNucleotide = sequence.charAt(indexOfFirstNucleotide);
            char secondNucleotide = sequence.charAt(index);
            if ((firstNucleotide == input) || (secondNucleotide == input)) {
                return true;
            }
            index++;
        }
        return false;
    }
}


第一次接触debug,实在不知道代码里面的bug在哪,只看出结果是错误的。麻烦各位指点一下。
搜索更多相关主题的帖子: java  Debug  代码  

----------------解决方案--------------------------------------------------------
打个断点 一直跟踪不就知道了
----------------解决方案--------------------------------------------------------
回复 2# guoxhvip 的帖子
就是还不会这些啊,正在学……
可以先告诉一下bug是什么吗?
----------------解决方案--------------------------------------------------------
  相关解决方案