Nie wiem dlaczego program usuwa tylko trzy pierwsze wyrazy z listy, dodaje je na koniec i usuwa teraz ostatni wyraz z listy. A przynajmniej tak to dla mnie wygląda .
Albo dodaje pierwszy pusty ciąg. Ale dlaczego ?
Coś jest nie tak
Rozwiązane
Komentarze (13)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
hidden #10690840
11 listopada 2021, 11:17
Witaj, najłatwiej będzie jak pokażesz kod, który zastosowałeś ;)
Co do usuwania to możliwe, że masz ustawione źle "nazwalisty".remove();
0
Paweł Knapik
11 listopada 2021, 14:26
Eee coś musiałem pomieszać przy dodawaniu pytania że nie ma kodu no i pod zadamiam ktorego dotyczy tez go nie ma wiec dodam jeszcze raz pytanie. Zadanie "Przestawiono w samą porę".
0
hidden #10690840
11 listopada 2021, 20:04
Oki. No to jak nie widzę Twojego kodu to powiem Ci mniej więcej jak powinno to od logiki wyglądać.
1. Pobieranie danych z klawiatury - 2 liczby.
2. Tworzenie listy
3. Pętla, która pobiera N razy ciągi z konsoli
4. Metoda, która m razy dodaje do listy i tym samym usuwa pierwszy element. np. To zadanie dla innych
5. Wyświetl tablicę
+3
Gellert Varga
12 listopada 2021, 08:52
I remonstrate against the publication of point 4.
I also remonstrate against the fact that many people here are pushing only this solution.
Maybe it's some "super-elegant" solution, but I think the purpose of CodeGym is to teach us to think.
It is very possible to solve this problem without your point 4, just by applying what you have learned so far, by thinking, by logic.
Paweł was also able to come up with a working method for the sorting problem, as you can see in his other post (he just ran into other difficulties.)
0
hidden #10690840
12 listopada 2021, 12:03
I'm not saying it's the best solution. This can be solved at least around:
The code is just bigger. This can be shortened.
Similarly, you don't do the BufferedReader / InputStreamReader object separately
+1
Lisa
12 listopada 2021, 12:08
Mr. Varga, please relax... all is good
- Have you seen some of the CG solutions? They introduce a lot of stuff never taught before.
- Do you really solely rely on CG lessons and do not read other sources? Doesn't even CG suggest we should read additional literature?
- You may not use IntelliJ but a lot of others do and CG advises us to use it. So if we're in IntelliJ, highlight the remove method and press shift-f1, guess what happens... the oracle java api documentation opens at exactly the remove methods description. It tells us that method has a return value... even the quick help (mouse over 'remove', wait a sec) offers that information. So this is by far no secret knowledge. Now applying the learned with some logic and thinking and you end up with the above posted code fragment. So what?
uhhh, no, again, I don't want to do that but I'm not able to resist... argh 😜🤪
+2
Gellert Varga
12 listopada 2021, 22:24
CyberRa:
Of course, everyone gets on as they want and as they can.
But I would like to point out that there are other options to solve this problem, not just the two solutions you mentioned here. That's why I don't like it when one solution out of many is over-promoted, giving the feeling that it's a "MUST SOLVE IT THIS WAY", and don't even think about it.
- And I'm not even sure that a shorter code is definitely better code.
- Of course, if this one-line solution is the obvious one for you, feel free to use it:) I surely don't want to determine who codes what and how... And I can't tell which solution is better or worse. I just like it when someone comes up with individual ideas.
Lisa: thanks for the tips.
0
hidden #10690840
13 listopada 2021, 12:27
I have not written that you have to do this. Without the code from the author of the post, it's hard to say what he would really like to help him. We cannot tell him where the error is and let him find out what is wrong.
And this list was in accordance with the terms of the assignment :)
0
Paweł Knapik
14 listopada 2021, 15:10
Problem był w tym ze pierwszy String mialem pusty i nie wiedziałem dlaczego ale juz mi gość pod zadaniem wytłumaczyl dlaczego.
0
hidden #10690840
16 listopada 2021, 08:46
Na przyszłość pokazuj kod, będzie łatwiej Ci pomagać :)
0
Paweł Knapik
16 listopada 2021, 08:48
Napisałem pod pierwszym komentarzem ze tu dodałem przez pomyłkę a pytanie z kodem znajduje sie pod zadaniem krórego dotyczy. :)
0
Gellert Varga
16 listopada 2021, 09:18
CyberRa:
you can find the code at Paweł's other post:
https://codegym.cc/help/16144
0
hidden #10690840
16 listopada 2021, 09:21
Nvm
0