“嘿,阿米戈!”
“你好,松鼠船長!”
“恭喜你完成關卡。在你超越之前,一定要完成這些編碼任務。”
3
任務
Java Syntax, 等級 9, 課堂 11
Dividing by zero
Maybe you've been wanting this for a long time, but you were afraid? Drum roll, please! Today we will divide by zero! You actually can do it, if you're careful. Create a public static void divideByZero method that divides any number by zero, and display the result of division. Wrap the method call in a try-catch block and display the exception's stack trace.
3
任務
Java Syntax, 等級 9, 課堂 11
Countdown
Students at the secret CodeGym center were given a task to assess their skills: write a countdown from 10 to 0 to determine how much time is left before the end of this test. Cool, huh? To create a delay, you need to use Thread.sleep(100), and wrap the sleep call in a try-catch block. Time's up!
6
任務
Java Syntax, 等級 9, 課堂 11
Method in a try-catch
Each of you at least once in your life has probably entered a password or other text incorrectly. Let's protect a program from accidentally entering "incorrect" data. In this task, the user enters numbers from the keyboard. If he or she enters something else, then an exception-catching method should be triggered and display all previously entered numbers.
12
任務
Java Syntax, 等級 9, 課堂 11
What's today's date?
Java has many tools that allow you to work with dates and times. Here we will use a Date object and SimpleDateFormat. Our task is this: the user should enter a date from the keyboard in the format "2013-08-18", and the application must convert the entered date into the format "AUG 18, 2013".
12
任務
Java Syntax, 等級 9, 課堂 11
Vowels and consonants
You and I both know very well which letters are vowels and which are consonants. We need to teach these concepts to intelligent robots, so we'll write a program to train them. The user will enter a string from the keyboard. Then a special method will help to split the entered data into two strings: one with all the vowels and another with only the consonants.
6
任務
Java Syntax, 等級 9, 課堂 11
A scary fairy tale
Once there were five classes: red riding hood, grandmother, pie, woodcutter, and wolf. Each class has 2 fields: ArrayList killed and ArrayList ate. Create the necessary objects (hood, grandmother, ...). Then arrange the relationships correctly according to who ate and/or killed who to bring to life what happened in the old Terran fairy tale "Little Red Riding Hood".
3
任務
Java Syntax, 等級 9, 課堂 11
Static modifiers are out of place
Faint steps could be heard, and then Master Yu Wu, an expert in the art of positioning objects, appeared in the room. He frowned at the code and said what the programmer was afraid to hear: "Where they are needed, the static modifiers are not. Your error herein lies". The master was correct: Rearrange the static modifiers so that the program compiles.
6
任務
Java Syntax, 等級 9, 課堂 11
List of number arrays
By Level 9, students are already adept at manipulating arrays and they know a thing or two about lists. Let's unify this knowledge by trying the following task. We'll create a list whose elements are arrays of numbers. Then we'll add to the list five array objects whose lengths are 5, 2, 4, 7, and 0, respectively. Finally, we'll fill the arrays with any data and display them on the screen.
6
任務
Java Syntax, 等級 9, 課堂 11
Ten cats
I'd like ten cats and Java expertise, please. Preferably at the same time! Not a problem, hang on: the program has a Cat class with a String variable name. You need to create a Map and add 10 cats represented by (name, Cat) pairs. Then get a Set of all cats from the Map and display it on the screen.
6
任務
Java Syntax, 等級 9, 課堂 11
The code won't compile…
A developer pensively scratching her head while reviewing code is a sign that it won't compile! You must resign yourself to such situations and not be nervous. Here's some practice: The program reads in two file names. It copies the first file to the location specified by the second file name. And yes, the program doesn't work. Fix the mistake.
6
任務
Java Syntax, 等級 9, 課堂 11
Let's make the code do something useful!
Old task: Enter 2 file names, and copy the first file to the location specified by the second file name. New task: Enter 2 file names, and copy the first file to the location specified by the second file name. If the file to be copied doesn't exist, then the program reports it and reads another source file name and only then reads the destination file name.
12
任務
Java Syntax, 等級 9, 課堂 11
Task about algorithms
The inhabitants of Planet Linear Chaos give their children sorting tasks instead of Rubik's cubes. Here's a pastime enjoyed by small ordered isomorphs. Knock yourself out: after the user enters a list of words (and numbers) from the keyboard, the program should display the words in ascending order, and the numbers in descending order.