Testeksamne, og andre ting
This commit is contained in:
25
Testeksamen/Loop.java
Normal file
25
Testeksamen/Loop.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.util.Scanner;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Loop {
|
||||
public static void main(String[] args) {
|
||||
Scanner console = new Scanner(System.in);
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
System.out.println("Please enter \"STOP\" to stop.");
|
||||
while (true) {
|
||||
System.out.print("Enter a word: ");
|
||||
String next_word = console.next();
|
||||
words.add(next_word);
|
||||
if (next_word.equals("STOP")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("Here are the word lengths:");
|
||||
for (int i = 0; i < words.size(); i++) {
|
||||
String word = words.get(i);
|
||||
System.out.println(word + " " + word.length());
|
||||
}
|
||||
System.out.println("The last word was \"STOP\" of course.");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user