"Tocmai stai din nou inactiv? Ești un robot! Roboții fac ceva tot timpul. Iată câteva exerciții pentru a te împiedica să ruginești. Dar mai întâi, câteva indicii:"
„Sfat 1:
Prin „listă”, de obicei înțelegem un ArrayList .”
„Sfat 2:
Un „șir” înseamnă un obiect String .”
„Sfat 3:
„Creați o listă de șiruri” înseamnă cel mai adesea următoarele: Lista ArrayList<String> list = new ArrayList<String>(); "
2
Sarcină
Java Syntax, nivel, lecţie
What sort of list is that?
Java programmers love their lists just as much as conscientious homemakers love their shopping lists and to-do lists. If you haven't fallen in love with them yet, it's time to start. And a programmer's love begins with code. So, in this task, we'll create a list of strings, add 5 different strings, and then display the size of the list on the screen. Then we'll display the contents of the list. Easy peasy!
10
Sarcină
Java Syntax, nivel, lecţie
Longest string
Let's measure strings! And we'll complete a programming task at the same time: create a string list, read 5 strings from the keyboard, and add them to the list. Then use a loop to find the longest string (or longest strings, if there is more than one). A country should know its heroes: the longest strings will be displayed.
5
Sarcină
Java Syntax, nivel, lecţie
Expressing ourselves more concisely
Brevity is the soul of wit. In the this task, let's celebrate brevity by doing the following: create a list, read 5 strings from the keyboard, add them to the list, find the shortest string, and then display it. If several strings are shortest, we'll display them all, each on a new line. Any questions, private?!
2
Sarcină
Java Syntax, nivel, lecţie
To the top of the list
Imagine people making appointments at a dental office where the waiting list acts like a stack rather than a queue: the last person to schedule is the first to have a drill taken to his or her tooth. We'll write a program that reflects this unusual situation: create a list and add 10 strings, but we'll add them to the beginning of the list rather than the end.
5
Sarcină
Java Syntax, nivel, lecţie
Remove and insert
Manipulating lists in Java is almost as easy and enjoyable as manipulating people! Anyway, about those lists. Here's what you need to do: create a list and add 5 strings. Then remove the last string and insert it at the beginning. Repeat this manipulation 13 times and then display the contents of the list. Why? Don't ask, just believe: it's necessary.
10
Sarcină
Java Syntax, nivel, lecţie
Shortest or longest
Java games with lists are very popular. This makes sense, since they are all so simple and interesting. Join in the fun! In this task, we create a list of strings. Then we add 10 strings from the keyboard. The most interesting part is that we'll determine whether the shortest string or the longest string is encountered first in the list. If more than one string is shortest or longest, we'll consider the very first one we encounter.