English subtitles

← Draw a Flag with Three Colors - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

  1. Here is the French flag with three colors blue, white, and red. So, here it
  2. looks like we have to make three decisions. Are we in the first third, the
  3. middle third, or the last one? In java you would start out with the first
  4. condition, and I'll leave it to you to fill in the details in the exercise.
  5. Then, for the next part, you'll use an else if clause, so you simply write else
  6. if followed by another condition. And finally, you use an else for the
  7. remaining possibility. So, here you need to supply two conditions, is the point
  8. in the left, is it in the middle or otherwise, of course, it has to be in the
  9. rightmost part. This construction with if, else if. You can have other answers
  10. if you'd like. And then, finally is a else. This is what you do anytime you get
  11. multiple decisions. And I get worked down from the top to the bottom as you
  12. would expect. The first condition gets checked if it's fulfilled the statement
  13. is executed in here, and everything else is skipped. On the other hand, if the
  14. first condition wasn't true, one would move to check the second condition and
  15. if that one was true, it would be executed. If it wasn't, then the third one
  16. would be executed. In other words, exactly one of these three blocks is
  17. executed, depending on which condition is true or whether none of them is true.
  18. Well, now it's your turn to try that with the French flag. Again, you'll be
  19. given a point x y that could fall anywhere within the flag. And you need to
  20. make a decision whether to return blue, white, or red. And when you do that be
  21. sure to use an if, else if, else construction.