I have a problem en Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have a problem en Java

I have a problem, let's say I have a stack of numbers and the user is asked for a number to compare with all the elements of the stack and to know if it is greater or less.

15th Mar 2020, 10:04 PM
123456
123456 - avatar
4 Answers
+ 2
Please show us your code as this will allow the community to address your problem correctly. Please use the 8 rules for getting help from the community. https://www.sololearn.com/Blog/38/8-simple-rules-to-get-help-from-the-community Thanks and happy coding
15th Mar 2020, 10:09 PM
BroFar
BroFar - avatar
+ 2
you should specify your problem more. 😅 lets say the input is called x. one might understand x needs to be greater than every element of the stack. one might understand x needs to be greater than the average of all elements in the stack. one might understand x needs to be greater than the sum of all elements of the stack. one might understand x needs to be greater than half of the elements of the stack. one might understand x needs to be greater than the smallest number in the stack. you see, the problem is not really clear 😅 besides what do you have trouble with? -theorie behind algorithm -implementation of algorithm -implementation of Stack ...
15th Mar 2020, 10:18 PM
Anton Böhler
Anton Böhler - avatar
+ 1
I am having trouble implementing the algorithm. What I will explain, for example, create a stack and add 8 and 9, and then after the user is asked to enter an x ​​number, they will have to compare it to ALL THE ELEMENTS THAT MAKE UP THE BATTERY. So it is already clearer. AND IF THE X IS LESS THAN THE NUMBER OF THE STACK. IT WILL LAUNCH A MESSAGE IN CONSOLE THAT WILL SAY LESS IF IT WOULD NOT BE GREATER.
16th Mar 2020, 2:05 AM
123456
123456 - avatar
16th Mar 2020, 7:15 AM
Anton Böhler
Anton Böhler - avatar