Home Answers Viewqa Java-Beginners java using Stack

 
 


jandi
java using Stack
1 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners

How convert decimal to binary using stack in java?
whats the java program or code to that.
Thank you rose india and java experts
View Answers

August 11, 2010 at 12:45 PM


Hi Friend,

Try the following code:

import java.util.*;

public class ConvertDecimalToBinaryUsingStack
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = input.nextInt();
Stack<Integer> stack = new Stack<Integer>();

if(num == 0) {
System.out.println("BINARY is 0000");
}
else if(num == 1) {
System.out.println("Binary is: 0001");
}
else {
while(num != 0) {
int a = num/2;
int b = num%2;
stack.push(b);
num = a;
}
}

while(!stack.empty()) {
System.out.print(stack.pop());
}

System.out.println(" ");
}
}

Thanks









Related Pages:
Stack
Stack  How to implement a stack using classes in java?   Here is an example that implements a Stack class based on arrays. public class Stack { private int top; private int[] storage; Stack(int
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java? whats the java program or code to that. Thank you rose india and java... the number: "); int num = input.nextInt(); Stack stack = new Stack
Java Stack - Java Beginners
Java Stack  Can you give me a code using Java String STACK using the parenthesis symbol ( ) the user will be the one to input parenthesis......) if Open parenthesis push it to stack otherwise Pop the stack Thank you
Java collection Stack example
Java collection Stack example  How to use Stack class in java... :- -1 Description:- The above example demonstrates you the Stack class in java collection. We are using three methods of Stack. push(object items): The push
Java String using STACK - Java Beginners
Java String using STACK  Can you give me a code using Java String STACK using the parenthesis symbol ( ) it tells its Valid or Invalid it tells it excess parenthesis if Open parenthesis push it to stack otherwise Pop
how can create album in java by using Stack ....
how can create album in java by using Stack ....  hi all , if i press push button put the image to the stack , and when i press pop button remove the image ..??? please help me please
ADT stack - Java Beginners
ADT stack  Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using....  Hi Friend, Try the following codes: ADT Stack: import
ADT stack - Java Beginners
]. 2)Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list... Lisp-like list in Java. Write basic operations such as 'car', 'cdr', and 'cons
stack in java/
stack in java/  java code for stack push pop and display operation? thanks
Example of Java Stack Program
Example of Java Stack Program     ... it. Here in the example describes the methods to prepare an example of Java stack... are using two methods of Stack. push(Object item): It pushes an item onto the top
Java get Stack Trace
Java get Stack Trace       In this section, you will learn how to obtain the stack trace... to print out the exception stack trace to catch the error instead of using
stack using linked list
stack using linked list  how to implement stack using linked list
Revisiting Stack Trace Decoding,java tutorial,java tutorials
Revisiting Stack Trace Decoding 2003-01-28 The Java Specialists' Newsletter [Issue 063] - Revisiting Stack Trace Decoding Author: Dr. Heinz M. Kabutz.... Welcome to the 63rd edition of The Java(tm) Specialists' Newsletter sent
How to Print a Stack Trace Message
How to Print a Stack Trace Message  Debugging of Java program requires... if you print a stack trace from the exception using the printStackTrace... your problem at Discuss: printStackTrace in JSP. As we have seen that java
Java get Stack Trace as String
Java get Stack Trace as String       In this section, you will learn how to get the stack trace... an IllegalArgumentException using Throwable class. throwable.printStackTrace
java technologies stack
java technologies stack  java technologies stack
Java Stack
Java Stack       The Stack class works on the principle last-in-first-out (LIFO) stack of objects... java stack click on the link: http:/www.roseindia.net/java/beginners/stack
Stack Overflow - Java Tutorials
Stack Overflow in Java A stack is the part of the memory. The local automatic variable is created on this stack and method arguments are passed. When a process starts, it get a default stack size which is fixed for each process. 
stack and queue - Java Beginners
stack and queue  write two different program in java 1.) stack 2...://www.roseindia.net/java/example/java/util/StackImplement.shtml http://www.roseindia.net/java/example/java/util/QueueImplement.shtml Hope
Java stack help
Java stack help  How would I use stacks in java to do a calculation like: 4*((3+3)/(5-3
stack - Java Beginners
on Stack visit to : Thanks   http://www.roseindia.net/java... that inputs a line of text and uses a stack object to print the words of the line... : import java.io.*; import java.util.*; public class StackExample{ Stack stack
Generic Java Stack
Generic Java Stack  Hi here the question the interviewer asked me- package jp.co.worksap.intern; /** *The Stack class represents a last-in-first-out(LIFO) stack of objects *And this class can look at the object
can Stack accept imageIcon ..??
can Stack accept imageIcon ..??  how can write program like album ..by using Stack as an ideas datastracture and using imageIconb ?? please help me ..thanks alot
Java Stack Example
Java Stack Example In this section you will learn about Stack class  in java, how to use Stack in java. Before going into details we should know what... the item in the stack and how far it is from top of stack Example : A Java code
calculator in java with stack
calculator in java with stack  i want calcultor with interface in java and in interface there is button called postfix ,,, when the user enter opertions and numbers first check if is vaild or not then convert to postfix
Implementing a Stack in Java
Implementing a Stack in Java       In this section, you will learn how to implement a stack in Java. A Stack is like a bucket in which you can put elements one-by-one
Collection : Stack Example
Collection : Stack Example In this tutorial we will describe implementation of stack with example. Stack : Stack is based on concept of LIFO(Last In First... one access point that is top of stack. There are two main methods of stack
Push and Pop operation of stack.
operation of stack. In the previous tutorial is clearly explained the push pop operation. The drawback of implementing stack is that the size of stack...;stdlib.h> void push(int stack[], int *top, int value) { if(*top < 4
Java Stack ADT
Java Stack ADT You all are familiar with the data structure 'Stack'. The Stack ADT is same as Stack. It is a LIFO data structure where insertions and deletions always occur at the same end. This end is called the top of the stack
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Stack Implementation java code - Java Beginners
Stack Implementation java code  Hello roseindia and java experts can u help me.can you give me a code for this sir/maam.thank you so much. STACK IMPLEMENTATION -expression evaluator *GIVEN a String of expression, create
How to match a string symbols using the INDEX and the method use Stack
How to match a string symbols using the INDEX and the method use Stack   How to match a string symbols using the INDEX and the method use Stack it will determine balance or not balance ...use the STACK
Push and Pop operation of stack using linked list.
operation of stack using linked list. In the previous tutorial the stack operation in done using array. Code: # include <stdio.h> # include <...) { struct node *temp; if(p==NULL) { printf(" The stack is empty and cannot
How to match a string using the INDEX and the method use Stack or Queue?
How to match a string using the INDEX and the method use Stack or Queue?  Design a parser that parse the given string and counts the member of character that match the given data by INDEX position.using the STACK or QUEUE
Reverse String using Stack
Reverse String using Stack You all are aware of Stack, a data structure... the string using these operations. Here is the code: import java.util.*; class StackReverseString { public static String revString(String str) { Stack
How to Print a Stack Trace Message
How to Print a Stack Trace Message        As we have seen that java provides a method... information about the error process if you print a stack trace from the exception
Printing a Stack Trace to the Server Console
Printing a Stack Trace to the Server Console... the Stack Trace is printed on the Console. When you generate an exception in a program, it will be better to print out the exception stack trace to catch
Stack
Stack Overview Stack follows the rule of last in first out rule. Mainly two action are performed by stack one is push and other is pop. The last thing which we placed or push on stack is the first thing we can get when we pop. A stack
Define stack
Define stack  hii, Explain stack
Define stack
Define stack  hii, Explain stack?   hello, Stack is an ordered list in which all the insertions and deletions made at one end called top of the stack. It is referred as LIFO list. Last inserted item is deleted First
How can I write a GUI stack program by Java to push Image files instead of other data type items?
How can I write a GUI stack program by Java to push Image files instead of other data type items?   How can I write a GUI stack program by Java... wish to give the name of the image file to add it in to the stack, and set the pop
ARRAY and STACK
and STACK?   hii, STACK follows LIFO. Thus the item that is first entered... order.   a stack is simply a special case of an array. You could say that a stack uses user defined methods to remove and add contents to an array
Array stack
Array stack  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input and prints them in reverse order
Array stack
Array stack  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input and prints them in reverse order

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.