0

Write a program that runs a string of lengths N, so that loading elements into string a is the other way around.

thhis is my code:

ArrayList<String> niz = new ArrayList<String>();

System.out.print("Unesite N: ");
int n = s.nextInt();

for (int i = 0; i < n; i++) {
    System.out.println("Unesite string: ");
    String slova = s.next();
    niz.add(slova);
}

for (int i = niz.size() - 1; i >= 0; i--) {
    System.out.print(", " + niz.get(i));
}

System.out.println();
System.out.println(niz);
pcsutar
  • 1,715
  • 2
  • 9
  • 14
Razmus
  • 11
  • 1
  • 1
    What exactly is your issue? – Scary Wombat May 12 '22 at 07:24
  • `Collections.reverse(niz);` – XtremeBaumer May 12 '22 at 07:27
  • will not memorize and memorize in a string. When I print it out of the loop, it remembers the original string that was entered. How to remember that inverted string and memorize it. And not to use Collections.reverse (string); – Razmus May 12 '22 at 07:30
  • 1
    Sidenote due to `ArrayList niz = new ArrayList();` - [What is a raw type and why shouldn't we use it?](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it) – maloomeister May 12 '22 at 07:35

0 Answers0