"Sitter du bare inaktiv igjen? Du er en robot! Roboter gjør noe hele tiden. Her er et par øvelser for å forhindre at du ruster. Men først, noen tips:"
"Hint 1:
Med 'liste' mener vi vanligvis en ArrayList ."
"Hint 2:
En 'streng' betyr et strengobjekt ."
"Hint 3:
'Opprett en liste over strenger' betyr oftest følgende: ArrayList<String> list = new ArrayList<String>(); "
2
Oppgave
Java Syntax, nivå, lekse
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
Oppgave
Java Syntax, nivå, lekse
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
Oppgave
Java Syntax, nivå, lekse
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
Oppgave
Java Syntax, nivå, lekse
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
Oppgave
Java Syntax, nivå, lekse
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
Oppgave
Java Syntax, nivå, lekse
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.