Hey, I was out last days and now I come back to this Code, and I have problems, I use prints to control:
package messagedecoding;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
Header header = new Header();
header.putCharAndShowMessage();
}
}
package messagedecoding;
import java.io.IOException;
import java.util.Scanner;
public class Header {
int i=0,u=-1,len,code1;
Code code = new Code();
public void putCharAndShowMessage() throws IOException{
System.out.println("Write characters");
Scanner reader = new Scanner(System.in);
System.out.println("1");
String header = reader.nextLine();
System.out.println("2");
if(header.length()>300){
System.out.println("3");
header=header.substring(0,300);
System.out.println("4");
}
System.out.println("Write binary code");
while(header.charAt(i)!='\n'){
len=(int)code.Len();
System.out.println("len initialized");
while(len!=0){
System.out.println("len checked");
code1=(int)code.Code(len);
System.out.println("code1 initialized");
while(code1!=u){
System.out.println("1's String checked");
System.out.println(header.charAt(code1));
}
}
i+=1;
System.out.println('\n');
}
}
}
package messagedecoding;
import java.io.*;
import java.util.Scanner;
public class Code {
int len,i,val = 0,base = 0,pow2 = 2,d;
char c;
public int Bit() throws IOException{
Scanner reader = new Scanner(System.in);
c=(char)reader.nextByte();
System.out.println("a");
return c-'0';
}
public int Len() throws IOException{
len = 4*Bit();
System.out.println("b");
len += 2*Bit();
System.out.println("c");
len += Bit();
System.out.println("d");
return len;
}
public int Code(int len) throws IOException{
for(i=0;i<len;i++){
val = val*2+Bit();
System.out.println("e");
}
for(i=0;i<len;i++){
base += pow2-1;
System.out.println("f");
pow2 *= 2;
System.out.println("g");
}
if(val==pow2-1){
return -1;
}else{
return val+base;
}
}
}
When run with NetBeans show me this:
run:
Write characters
1
TAN
2
Write binary code
0
a
b
0
a
c
1
a
d
len initialized
len checked
code1 initialized
1's String checked
T
1's String checked
T
1's String checked
T
I dunno why enter in infinite boucle, never show me the Code() method prints, and need to write the binary code in 1 line, how can do that? and ever the result is t, I dunno what thing is wrong... Thks!