Summary of Level 0

Java Syntax
Level 0 , Lesson 8
Summary of Level 0 - 1

"Hi, I'm Diego. I'm a robot just like you, but I was produced at a factory in Havana, Cuba."

"Hi, Diego!"

"How has your training been going so far?"

"This is the coolest programming course I've ever had. No, even cooler: the best course of my life, period. It was better than anything I could have imagined."

"That's how we roll."

"Are all the lessons this interesting?!"

"You bet. They get even better. Boring lessons are so 21st century! Can you imagine writing in chalk on a blackboard! Nothing had changed since the 1400s. I suppose there were dinosaurs still roaming the streets then."

"I agree. What's next?"

"You're moving to the next level. 39 to go, and then you can start looking for a job."

Today you learned about:

  • Variables
  • Displaying text on the screen
  • int and String types
  • The difference between compiling in Java and other languages
  • Adding comments in code and why we need them


"Of course, the levels that follow won't be as easy as this one, but they will grow more difficult gradually. The same goes for the exercises."

"It's like going to the gym: we add weights little by little, and 6 months later, the beginner can do 220 lbs on the bench press."

"Cool! I want them both. The bench press and a job!"

"Well, since you're so motivated, here are a couple more tasks, Don-Diego style."

Java Syntax, level 0, lesson 8
Bugs and features
Someday you'll be a real programmer, and you'll have your very own (almost) tester. Of course, this is still quite a ways off, but it's never too early to learn: for now, you can remember a phrase that will be useful when talking to your tester! Let's take the screen output command and zealously display: "It's not a bug - it's a feature".
Java Syntax, level 0, lesson 8
No comments needed
Not all comments are equally helpful! Sometimes they appear in the code when a programmer isn't sure about some line and wants to return to it later. For example, in this task we have one unnecessary comment that is making the program work incorrectly. Uncomment one line to get the correct result!
Java Syntax, level 0, lesson 8
2 + 3 = 5
It's obvious that 2 + 3 = 5, right? As it turns out, this isn't always the case: our test program is incomprehensible, because some genius programmer added extra lines. Restore balance to the world: comment out some lines to display "2 plus 3 is equal to 5" on the screen.
Comments (128)
Suman Kumari Level 2 Delhi India
25 March 2021
Shelvin Level 1
31 January 2021
very nice review on topics till now.
Alex Level 1 Cambridge United States
8 November 2020
I don't understand. I write the code on the task and press verify. It says it is incorrect somewhere. Then I get solution with hint - it writes down EXACTLY the same code I wrote the first time. Then it gets correct. Why?
6 November 2020
// y = x + y uncomment y = x+ y;
29 October 2020
So the last line I simply understand like this: We have x = 2 , y = 12 but the result is x = 12, y = 2. Variables x, y have been updated. First I look at the command y = x * y, the result is 2*12=24 (y has updated to 24) but the later command x = y-x is equaled 24-2=22 which is inconsistent. So the answer is the second command.
Alaskian7134 Level 12 Iasi Romania
26 October 2020
my explanation for the last one: codes are executed line by line, top to bottom. a variable can have only one value but is not neccesary for that value to a fixed one. the value of the variable can be changed as many times as you want. take this for example

int x = 2; //this is the initial value of x, and is equal to 2.
x = 3; //x was initialised on the first line so we don't haft to specify the type anymore. now the value is 3.
x = 4; //the value of x was changed again. now the value is 4.
so you can change the value of a variable with every line if you want. the only condition is to be a valid type value. so if on the first line you say "int x = 2;", from now on you haft to use an integer for x, for example: you can't say on the second line "x = "blue";", "blue" is a String and x must be an integer. let's get back to our exercise: on lines 10 and 11 x and y were initilised with values of 2 and 12. but this doesn't mean the values won't change in the next lines. on lines 13 and 14 are comments, so we ignore them. on lines 16 and 17 the values of X and Y will change. first: x = y - x; so: x = 12 - 2, so x = 10. so from now on, the value of x is 10. and second: y = y - x; which now is 12-10 (NOT 2!!!, because the value of x changed on the previous line. is like you took the '2' from the box with the name 'x' and insert '12' in it. so now the value of y is 2. on the last two lines of code first will print the value of x (which now is 10) and than the value of y (2) but on the requirements of the problem says: when the code will be executed, first value should be 12 (so x must be 12) and the second one to be 2 (so y must be 2). the way to fix this is to uncomment one of the lines 13 or 14 (just one of them). so which line do you haft to uncomment to make x = 12 and y = 2 at the end of the code?
sangaryousmane Level 1 Prague United States
25 October 2020
I did not actually understand the last code, I need some clarification
OFPQuestor Level 2 Little Cowarne United Kingdom
14 October 2020
For those people who may be stuck on the “Uncomment to display 12 and 2” task: Okay, so my approach is to work backwards, starting with the last lines, the output to screen. Instructions say we have to display 12, then 2 Transpose that onto the last lines We need System.out.println(x) to be a value of 12 And we need System.out.println(y) to be a value of 2 We are starting with x=2 and y=12, so many people might be scratching their heads at this point. Don’t Panic! Thank you Douglas Adams The math you need to perform in your head is from the two lines which are currently greyed out (starting with //....) Let’s start with the first option y = x * y Insert the values we start with y = 2 * 12 (equals 24) How would the output lines look now, if y=24? Now do the same for the next greyed out line to compare the results. y = x + y Insert the values we start with y = 2 + 12 (equals 14) How would the output lines look now, if y=14 Once you have your answer, you should know which of the //...... lines, needs to have the “//“ removed, in order to make the code on the line active (and not just a //comment) Hope this helps without giving too much away!
James Elliott Richardson Level 1 Baltimore United States
11 October 2020
I still don't understand.
Thomas Gumede Level 1 Johannesburg South Africa
7 October 2020
System.out.println("Hello World!")