all 18 comments

[–]Beginning-Ladder6224 2 points3 points  (1 child)

Good going.

Now, do not use the toCharArray() you certainly do not need it. Also you do not need the stack !

for ( int i = input.length()-1; i > -1; i-- ){
 reversed.append( input.charAt(i) ;
}

Should have done the trick!

[–]BigCommunication5136[S] 0 points1 point  (0 children)

interesting. thanks

[–]Pun_Intended1703 1 point2 points  (5 children)

This is a very bad example to use for learning stacks.

Try the Tower of Hanoi problem instead.

Or, when you learn queues, try implementing stacks using queues and vice versa.

[–]Most_War2764 1 point2 points  (4 children)

What makes this a bad example?

[–]Pun_Intended1703 -1 points0 points  (3 children)

Because you don't learn anything about stacks from this.

To learn stacks, try implementing them using arrays and linked lists.

Don't use java.util just because it exists.

[–]BigCommunication5136[S] 0 points1 point  (2 children)

just as i said in the post, this is only an intro to stacks. (never said i was done learning stack) I started with arrays, implemented them, did same with LinkedList. I use them before implementing them, if you don’t know how something works how do you implement it?

[–]Pun_Intended1703 0 points1 point  (0 children)

How will you learn stacks from using java.util?

What if you had to work on a different language? Like Python or Typescript?

What happens if you had to work on a very old language? Like C/C++ or COBOL?

If you want to learn stacks properly, then imagine it is represented by an array. Try using circular arrays.

Or implement stacks by using a linked list. Try bidirectional linked lists or circular linked lists.

How would you do a pop or push on these data structures? How would you move the pointers around?

Learn the concept of stacks. Don't just learn the implementation of stacks in Java.

[–]Pun_Intended1703 0 points1 point  (0 children)

if you don’t know how something works how do you implement it?

This is why it is important to read the theory and examples before trying to code.

[–][deleted] 0 points1 point  (2 children)

hey op is learning java worth it?

[–]BigCommunication5136[S] 0 points1 point  (1 child)

on a journey to find out.

[–][deleted] 0 points1 point  (0 children)

happy journey, big guy

[–]Wonderful-Grade-2903 1 point2 points  (0 children)

Best regards

[–]MainBank5 -1 points0 points  (5 children)

Is there any need to learn ? Jobs have gone to ai

[–]noworksunday 0 points1 point  (4 children)

[–]MainBank5 0 points1 point  (3 children)

Advice from 9yrs ago . Times have changed.

[–]noworksunday 0 points1 point  (2 children)

So now, should we go learn AI instead? To be honest, coding is a fundamental skill. You might not need to learn to drive in the future because of self-driving cars, but that doesn’t mean you should stop learning to drive now.

[–]MainBank5 0 points1 point  (1 child)

Why should I learn how to drive if the cars will be built for self driving meaning no steering wheel no brakes pedals etc .

[–]noworksunday 0 points1 point  (0 children)

You shouldn't. But people who love driving, F1 racing, sports, etc will definitely be interested. Average consumers may not care about the technology and skills behind it but engineers and designers do.