这里的问题是由于某种原因没有输入 for 循环内的条件。也就是说 if (samp==1){
,由于所有字符都应该是 0 或 1,因此应该始终输入这两个字符中的一个,而不是输入它们中的任何一个,我不确定发生了什么。这应该是一个简单的字符比较。我还对其进行了测试,以查看“samp”变量一次正确地对位序列采样一个字符。
真的可以在这里使用一些帮助。我相信它的头脑简单得令人麻木。
//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);
}