1

ここでの問題は、何らかの理由で for ループ内の条件が入力されていないことです。つまり if (samp==1){、すべての文字は 0 または 1 である必要があるため、どちらも入力されず、何が起こっているのかわかりません。単純な文字比較である必要があります。また、「samp」変数が一度に 1 文字ずつビット シーケンスを正しくサンプリングしていることを確認するためにテストしました。

ここで本当に助けが必要です。その心は麻痺するほど単純だと確信しています。

//This method will take in a binary bit sequence which should be set up correctly from above
    //Then it should print the Unipolar encoding of the waveform
    public static void Unipolar(String s){
        String code ="";
        char samp='9';
        char[] charArray = s.toCharArray();  //turn the input bit sequence into a char array for simplicity

        String topline="";     //the method I chose was to keep a consistent 3 strings to draw the output
        String midline="";
        String botline="";



        for (int i = 0; i < s.length(); i++) {
        samp = charArray[i];
        System.out.println(samp);
            //depending on if the current character is a 1 or a 0 a differnt pattern will be added to the 
            //string to be outputted
            if (samp==1){
                topline+="*****"; 
                midline+="*    ";
                botline+="*    ";
            }
            if (samp==0){
                topline+="     ";
                midline+="     ";
                botline+="*****";
            }
        }
        System.out.println(topline);
        System.out.println(midline);
        System.out.println(botline);
    }
4

2 に答える 2

1

比較するときは、文字値を使用する必要がありますchars

if (samp == '1') {
   ...
于 2012-10-19T23:30:07.290 に答える
0

気にしないでください....問題は、これが正しい比較演算子であることを意味する0または1を一重引用符で囲む必要があることです。

if (samp=='0'){ 
于 2012-10-19T23:30:16.093 に答える