0
這裏是我的代碼:我二進制轉換器不知何故這麼想的工作
import java.util.*;
public class binary{
public static void main(String args[])
{
//input thing
Scanner read = new Scanner(System.in);
//variables
String result = "";
int input;
//input
input =read.nextInt();
toBinary(input,result);
System.out.println("Your binary is" + result);
}
public static String toBinary(int a,String b){
StringBuilder sb = new StringBuilder();
int y;
int z=2;
while(a >= 1){
y = a%2;
a/=z;
sb.append(y);
}
b = sb.toString();
invert(b);
return b;
}
public static String invert(String s) {
String temp = "";
for (int i = s.length() - 1; i >= 0; i--)
temp += s.charAt(i);
return temp;
}
}
你能不能幫我什麼是錯,導致回報是空白。當我輸入一個數字時,它會顯示爲「你的二進制文件」。
到底什麼是變量的新對象引用。我只做了10天的Java ... – DarkWyvren 2014-10-05 01:13:22
@DarkWyvren有關對象和對它們的引用的更多信息,請參閱以下鏈接:http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-傳遞值 - http://docs.oracle.com/javase/tutorial/java/javaOO/usingobject.html - http://www.c4learn.com/java/java-assigning-object-reference/ - http :?//www.kdgregory.com/頁= java.refobj – Tom 2014-10-05 08:39:01