What's new

Closed Stacks Java

Status
Not open for further replies.

Ve3

Eternal Poster
Established
Joined
Apr 21, 2017
Posts
1,221
Solutions
1
Reaction
292
Points
449
Pa help naman po kung pano ma access ung value ng stk.pop() para amalagay ko sa file write. di ko kasi malan gagawin ko. lol
Screenshot (115).png
 

Attachments

Return value ng pop() is string so pwede mo ilagay sa string variable yung value.
string binaryValue = stk.pop();
 
Bale sa code mo. Hindi ko alam kung pwede iadd ang string or something concatenation
Ilagay mo yung value ng stk.pop sa isang string something sa loob ng while loop mo
binaryValue += stk.pop()

Sorry. C# programmer ako.
 
Bale sa code mo. Hindi ko alam kung pwede iadd ang string or something concatenation
Ilagay mo yung value ng stk.pop sa isang string something sa loob ng while loop mo
binaryValue += stk.pop()

Sorry. C# programmer ako.
Tama paps para isang call lang ng System.out.print(), I think need pa i-convert sa string before mag concat para tama ang value :D.
 
You already know how to do it (ASSUMING you're the one who created that program).

Look how you access FileWriter. You stored it in a variable. Why did you store it in a variable? So you can access it later. Same idea with .pop().
 
  • Like
Reactions: Ve3
You already know how to do it (ASSUMING you're the one who created that program).

Look how you access FileWriter. You stored it in a variable. Why did you store it in a variable? So you can access it later. Same idea with .pop().
sir nag eeror pag nilagay ko sa isang variable
 
You already know how to do it (ASSUMING you're the one who created that program).

Look how you access FileWriter. You stored it in a variable. Why did you store it in a variable? So you can access it later. Same idea with .pop().
nag e error sir
 
Hi! Late na 'to pero susubukan ko hehe, compile-time or runtime error? Kung compile time check mo routine ng stk.pop() , kung nainitialize mo na or kung static method, kasi kung ang return value ng stk.pop eh string, di ko alam kung paano mo nakukuha yung error :)

Saka ts, 'yung for loop mo pwede mo na tanggalin kung 1 lang max conditional niya para di overhead, kung di mo na balak palitan si 1
 
I don't know how you got an error but this is how simply you utilized .pop method of Stack.

Java:
import java.util.*;

public class HelloWorld{

     public static void main(String []args){
        
        int num = 12;
        Stack<Integer> stk = new Stack<Integer>();
        
        while(num != 0){
            
            int res = num % 2;
            stk.push(res);
            num /= 2;
        }
        
        while(!(stk.isEmpty())){
            
            System.out.println(stk.pop());
        }
     }
}
 
Status
Not open for further replies.

Similar threads

Back
Top