เฮ้ ฉันกำลังพยายามแปลง int ทศนิยมเป็น binary int จริงๆ โดยไม่ประสบความสำเร็จ
โปรดช่วยฉันด้วย
และฉันไม่ต้องการทำให้เป็น 'System.out.println()' เพราะฉันได้ทำไปแล้ว
ขอบคุณ!
`ฉันต้องการฟังก์ชันแบบเรียกซ้ำที่ได้รับ int ทศนิยมและส่งกลับ int ไบนารี
public static void decToBin(int number) {
if(number == 0)
return ;
decToBin(number / 2);
System.out.print(number % 2);
}
ว่ามันเป็นสิ่งที่ฉันทำ...
เมื่อฉันพยายามรับสตริง:
public static String decToBin(int number) {
if(number == 0)
return "";
return new Integer(number % 2).toString() + new Integer(decToBin(number / 2)).toString();
}
ข้อผิดพลาด...
System.out.println
? - person Pshemo   schedule 25.05.2014String
หรือไม่?StringBuilder
น่าจะทำงานด้วยได้ง่ายกว่า - person Pshemo   schedule 25.05.2014