| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 801 人关注过本帖
标题:Debug java代码
只看楼主 加入收藏
ddww11
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-3
收藏
 问题点数:0 回复次数:2 
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 代码 
2008-10-03 20:44
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 
打个断点 一直跟踪不就知道了

愛生活 && 愛編程
2008-10-04 00:24
ddww11
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-3
收藏
得分:0 
回复 2# guoxhvip 的帖子
就是还不会这些啊,正在学……
可以先告诉一下bug是什么吗?
2008-10-04 12:32
快速回复:Debug java代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046222 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved