Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 读取十进制数并打印其等效的二进制数_Java_Stack - Fatal编程技术网

Java 读取十进制数并打印其等效的二进制数

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

如何编写主方法读取十进制数并打印其等效二进制数

分三节课写 类别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.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));
}