「こんにちは、兵士さん!」
「こんにちは、リス船長さん!」
「素晴らしいニュースがあります。スキルを強化するための演習をいくつかご紹介します。毎日取り組めば、あなたの能力は飛躍的に成長します。これらは IntelliJ IDEA 用に特別に設計されました。」
3
タスク
Java Syntax, レベル 10, レッスン 11
Correct answer: d = 2.941
A spaceship flew to planet of Paleo-Know, and met there creatures that didn't even know integer arithmetic. But this whole story has nothing to do with our task. It's only here as an amazing fact to get your attention. Meanwhile, you need to add one cast operation to the code and get the correct answer.
3
タスク
Java Syntax, レベル 10, レッスン 11
Correct answer: d = 5.5
Be careful with narrowing conversions! This technique can lead to unexpected results. Remember this all your life, but for now—solve a small type conversion task. The code is already written, but something is missing, specifically one cast operation. Find where it needs to get the correct answer.
3
タスク
Java Syntax, レベル 10, レッスン 11
Correct answer: d = 1.0
Before completing the final level of the first quest, students at the secret CodeGym center already know well the difference between 1 and 1.0. And it's a good thing too, otherwise "type conversion" would be completely incomprehensible. Let's look for a suitable place in previously written code: We need to add one type conversion to get the correct answer.
3
タスク
Java Syntax, レベル 10, レッスン 11
Big salary
Oh, laziness! Your loyal apologists are everywhere! You're an engine of progress and a destroyer of dreams. Even the person currently reading these lines has certainly been under your influence, thinking, "Why do I need Java anyway. It's so much work!" We have a task especially for you: display the phrase "I do not want to learn Java. I want a big salary". And do it 43 times.
「以前の演習は新人向けでした。ベテラン向けに、さらに高度なボーナス演習を追加しました。ベテラン向けです。」
12
タスク
Java Syntax, レベル 10, レッスン 11
Number of letters
Have you ever thought that there are too many letters in the alphabet? Computers are able to get by quite well with two, but we have 26. This is an inadmissible excess! Still, we do have to accept reality and complete relevant tasks. Here's one: Enter 10 strings from the keyboard and count the number of different letters in them.
6
タスク
Java Syntax, レベル 10, レッスン 11
Human class constructors
People are different. And each person differs in significant ways. Suppose we have a newborn who has only a name and a mother. Or suppose we have a musician that prizes his band and his ability to perform. Let's write a Human class with 6 fields and come up with 10 different constructors for it. Each constructor should make sense.
3
タスク
Java Syntax, レベル 10, レッスン 11
Use the fewest number of static modifiers
"Fewest statics, maximum result" is the motto for your next task. It will require you to analyze code already written by some good soul, and understand where this kind person forgot to put static modifiers. The code won't compile. But don't stick them everywhere. Try to use them as little as possible.
6
タスク
Java Syntax, レベル 10, レッスン 11
Array of string lists
Sometimes a task is just a task. With no dirty tricks, and no need to look for complexity or depth. You just need to sit down and do it. Just such a task is before us. See how everything is clear and simple: create an array whose elements are lists of strings. And then fill the array with any data and display it on the screen.
6
タスク
Java Syntax, レベル 10, レッスン 11
Identical words in a list
Searching for duplicates and matches is a favorite exercise for programmers. Let's do this: use the keyboard to read a list of 20 words and count how many identical words the list contains. We'll represent the result as a Map, where the key is a unique string, and the value is the number of times this string occurs in the list.
3
タスク
Java Syntax, レベル 10, レッスン 11
Safe retrieval from a list
Once upon a time there was a list of integers. Everything would have been fine, but it lacked a method to safely retrieve the numbers. Take pity on the list and create such a method for it. It must return a list item based on its index. If an exception occurs while retrieving an element, it must be caught, and the method should return defaultValue.
3
タスク
Java Syntax, レベル 10, レッスン 11
Corrections are needed
Other people's mistakes once again block our path to a brighter future. On the contrary, maybe they actually form the path: it's hard to become a programmer without them. Take this non-functioning program and rework it so it compiles. It demonstrates how a HashMap works: read pairs (a number and string) from the keyboard, put them in a HashMap, and then display its contents.
12
タスク
Java Syntax, レベル 10, レッスン 11
Functionality is not enough!
Old task: Read pairs (a number and string) from the keyboard, and then display them on the screen. New task: Read the same pairs from the keyboard and store them in a HashMap. Any empty input string signifies the end of data entry. The numbers can be repeated, but not the strings. The entered data must not be lost! Then the program should display the contents of the HashMap on the screen, each pair on a new line.
3
タスク
Java Syntax, レベル 10, レッスン 11
Task about algorithms
We received a new children's assignment from the ordered isomorphs on Planet Linear Chaos. You remember that it was these weirdos who thought up all sorts of sorting techniques and constantly practice them. That's why these tasks are so strange. Check it out: read 30 numbers from the keyboard. Display the 10th and 11th smallest numbers. But, you know, you've got to try it!