Java 读取十进制数并打印其等效的二进制数
如何编写主方法读取十进制数并打印其等效二进制数 分三节课写 类别1:节点2:stackPtr3:stackPtrMain 我需要使用(s.push) 我想要一个例子 在输出中 (s.push(17);) 二进制中的十进制数17是10001 (s.push(20);) 二进制中的十进制数20是10100 (s.push(23);) 二进制中的十进制数23是101111 (s.push(26);) 二进制中的十进制数26是11010 生成成功(总时间:0秒)Java 读取十进制数并打印其等效的二进制数,java,stack,Java,Stack,如何编写主方法读取十进制数并打印其等效二进制数 分三节课写 类别1:节点2:stackPtr3:stackPtrMain 我需要使用(s.push) 我想要一个例子 在输出中 (s.push(17);) 二进制中的十进制数17是10001 (s.push(20);) 二进制中的十进制数20是10100 (s.push(23);) 二进制中的十进制数23是101111 (s.push(26);) 二进制中的十进制数26是11010 生成成功(总时间:0秒) 您只需将该函数与System.out.p
您只需将该函数与
System.out.println
组合,并添加到push方法中:
public void push(int x)
{
Node N = new Node(x); // create a new node with data x
N.next = top; // new node refer to the stack top
top = N; // the new node will be the stack top
System.out.println("The decimal number "+x+" in binary is "+Integer.toBinaryString(x));
}
public void push(int x)
{
Node N = new Node(x); // create a new node with data x
N.next = top; // new node refer to the stack top
top = N; // the new node will be the stack top
System.out.println("The decimal number "+x+" in binary is "+Integer.toBinaryString(x));
}