Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在类中包含来自另一个方法的print语句_Java - Fatal编程技术网

Java 如何在类中包含来自另一个方法的print语句

Java 如何在类中包含来自另一个方法的print语句,java,Java,我的问题是如何更改代码,以便它打印出我的第一行打印行以及从testBuildCodonMap方法打印的行?当前未打印的打印行是System.out.println(s+“\t”+codonMap.get(s))。我想把它包括在其他打印报表中 import java.util.*; import edu.duke.*; public class CodonCount { private HashMap<String,Integer> codonMap; public

我的问题是如何更改代码,以便它打印出我的第一行打印行以及从
testBuildCodonMap
方法打印的行?当前未打印的打印行是
System.out.println(s+“\t”+codonMap.get(s))。我想把它包括在其他打印报表中

import java.util.*;
import edu.duke.*;

public class CodonCount {
    private HashMap<String,Integer> codonMap;
    public CodonCount() {
        codonMap = new HashMap<String,Integer>();
    }
    private void buildCodonMap(int start, String dna) {
        //clear out map before building
        codonMap.clear();
        //This method will build a new map of codons mapped to 
        //their counts from the string dna with the reading frame
        //with the position start (a value of 0, 1, or 2).
        for (int index=start; dna.length() - index > 3;index+=3) {
            String currentCodon = dna.substring(index,index+3);
            if (!codonMap.containsKey(currentCodon)) {
                codonMap.put(currentCodon,1);
            }
            else {
                codonMap.put(currentCodon,codonMap.get(currentCodon)+1);
            }
        }
    }
    private String getMostCommonCodon() {
        //get the codon in a reading frame that has the largest count
        //this method assumes the HashMap of codons to counts has already been built
        int currentHigh = 0;
        String mostCommonCodon = "";
        for (String s : codonMap.keySet()) {
            int currentCount = codonMap.get(s);
            if (currentCount > currentHigh) {
                mostCommonCodon = s;
                currentHigh = currentCount;
            }
        }
        return mostCommonCodon;
    }
    private void printCodonCounts(int start, int end) {
        //This method prints all the codons in the HashMap along with their
        //counts if their count is between start and end, inclusive.
        for (String s : codonMap.keySet()) {
            if (codonMap.get(s) >= start && codonMap.get(s) <= end) {
                System.out.println(s+"\t"+codonMap.get(s));
            }
        }
    }
    public void testBuildCodonMap() {
        FileResource fileResource = new FileResource();
        String dna = fileResource.asString();
        dna = dna.toUpperCase();

        for (int index=0;index <= 2;index++) {
            System.out.println("\nTesting with start position "+index+":\n");
            buildCodonMap(index,dna);
            String mostCommonCodon = getMostCommonCodon();
            System.out.println("Total unique codons found: "+codonMap.size());
            System.out.println("\nMost common codon: "+mostCommonCodon
                                +"\t"+codonMap.get(mostCommonCodon));
            printCodonCounts(4,8);
        }
    }
}
import java.util.*;
进口杜克大学*;
公共类密码计数{
私有HashMap-codonMap;
公共密码帐户(){
codonMap=newhashmap();
}
私有void buildCodonMap(int start,字符串dna){
//建房前把地图清理干净
codonMap.clear();
//这种方法将构建一个新的密码子图谱,该图谱映射到
//他们的计数来自于读框中的字符串dna
//位置开始时(值为0、1或2)。
对于(int index=start;dna.length()-index>3;index+=3){
字符串currentCodon=dna.substring(索引,索引+3);
如果(!codonMap.containsKey(currentCodon)){
密码子MAP.put(当前密码子,1);
}
否则{
密码子映射put(currentCodon,密码子映射get(currentCodon)+1);
}
}
}
私有字符串getMostCommonCodon(){
//在具有最大计数的阅读框中获取密码子
//此方法假定密码子到计数的哈希映射已经构建
int currentHigh=0;
字符串mostCommonCodon=“”;
对于(字符串s:codonMap.keySet()){
int currentCount=codonMap.get;
如果(currentCount>currentHigh){
mostCommonCodon=s;
currentHigh=currentCount;
}
}
返回最常见的密码子;
}
私有void printCodonCounts(int开始,int结束){
//此方法打印HashMap中的所有密码子及其
//如果计数介于开始和结束之间(包括开始和结束),则计数。
对于(字符串s:codonMap.keySet()){

如果(codonMap.get(s)>=start&&codonMap.get(s)我明白了!需要将
printCodonCounts(4,8);
public void testBuildCodonMap()方法内部的
行更改为
printCodonCounts(1,3);

允许方法
私有void printCodonCounts(int start,int end)中的print语句
执行。

您是否使用调试器运行了代码以查看它为什么不打印?编辑后,我建议您发布一个@user1803551,我这样做了,CTG作为正在计算的密码子之一。但我没有找到其他内容。编辑的问题包括MCVE。您是否在代码中的任何其他地方调用
printCodonCounts
oes声明您正在某处调用它,并且它需要两个int,您在某处将其称为
printCodonCounts()
。您已经在提供的代码中调用了它一次,并且操作正确。