Here is the French flag with three colors blue, white, and red. So, here it
looks like we have to make three decisions. Are we in the first third, the
middle third, or the last one? In java you would start out with the first
condition, and I'll leave it to you to fill in the details in the exercise.
Then, for the next part, you'll use an else if clause, so you simply write else
if followed by another condition. And finally, you use an else for the
remaining possibility. So, here you need to supply two conditions, is the point
in the left, is it in the middle or otherwise, of course, it has to be in the
rightmost part. This construction with if, else if. You can have other answers
if you'd like. And then, finally is a else. This is what you do anytime you get
multiple decisions. And I get worked down from the top to the bottom as you
would expect. The first condition gets checked if it's fulfilled the statement
is executed in here, and everything else is skipped. On the other hand, if the
first condition wasn't true, one would move to check the second condition and
if that one was true, it would be executed. If it wasn't, then the third one
would be executed. In other words, exactly one of these three blocks is
executed, depending on which condition is true or whether none of them is true.
Well, now it's your turn to try that with the French flag. Again, you'll be
given a point x y that could fall anywhere within the flag. And you need to
make a decision whether to return blue, white, or red. And when you do that be
sure to use an if, else if, else construction.
Aquí está la bandera francesa con tres colores, azul, blanco y rojo. Así que, aquí
parece que tenemos que tomar tres decisiones. ¿Estamos en el primer tercio, el
tercio medio, o el último? En Java es conveniente empezar con la primer
condición, y te dejo a ti la parte de completar los detalles en el ejercicio.
Entonces, para la siguiente parte, vamos a usar cláusula «else if», por lo que simplemente vas a escribir «else
if» seguida por otra condición. Y, por último, vas a usar una «else» para la
posibilidad restante . Así pues, aquí es necesario que proporciones dos condiciones, está el punto
a la izquierda, en el medio o de otro modo, por supuesto, tiene que estar en la
parte más a la derecha. Esta construcción con «if, else if», puedes tener otra «else if»
aquí si quieres, y luego, finalmente, es «else». Esto es lo que se utiliza en cualquier momento en que necesites tomar
decisiones múltiples . Se van resolviendo desde arriba hacia abajo, como
podrías esperar. La primera condición se comprueba y, si se cumple la sentencia,
se ejecuta aquí, y todo lo demás se salta. Por otro lado, si la
primera condición no era cierta, pasaríamos a comprobar la segunda condición y
si ésta es cierta, se ejecutaría. Si no lo fuera, entonces se ejecutaría
la tercera. En otras palabras, se ejecuta exactamente uno de estos
tres bloques, dependiendo de qué condición es cierta o si ninguna de ellas lo es.
Bueno, ahora es tu turno para intentar esto mismo con la bandera francesa. Una vez más, se te
dará un punto x y que podría caer en cualquier lugar dentro de la bandera. Y tendrás que
tomar una decisión de si devolver azul, blanco o rojo. Y cuando lo hagas, asegúrate
de utilizar una construcción «if», «else if», «else».
Voici le drapeau français avec
trois couleurs bleu, blanc et rouge.
Ici, il semble qu'il faut
prendre trois décisions.
Sommes-nous dans le premier tiers,
le tiers moyen ou le dernier?
Dans Java, vous commenceriez
avec la première condition
et je vous laisse le soin de remplir
les détails de l'exercice.
Pour la partie suivante,
vous utiliserez une clause else if,
vous écrivez simplement else if
suivie d'une autre condition.
Et enfin, vous utilisez else
pour la possibilité restante.
Ici, vous devez fournir deux conditions:
le point est-il à gauche,
au milieu ou autrement,
bien sûr, il doit être dans
la partie la plus à droite.
Cette construction avec if, else if.
Vous pouvez avoir d'autres
else if si vous le souhaitez.
Et finalement, c'est un else.
C'est ce que vous faites chaque fois
qu'il faut prendre plusieurs décisions.
Et c'est traité de haut en bas
comme on pourrait s'y attendre.
La première condition est
vérifiée, si elle est remplie,
l'instruction est exécutée ici
et tout le reste est ignoré.
D'un autre côté, si la première
condition n'était pas vraie,
on se déplacerait pour vérifier
la deuxième condition
et si celle-ci était vraie,
elle serait exécutée.
Si ce n'était pas le cas, alors
la troisième serait exécutée.
En d'autres termes, l'un de
ces trois blocs est exécuté,
selon la condition qui est vraie
ou si aucun d'entre eux n'est vrai.
Maintenant c'est à vous d'essayer
ça avec le drapeau français.
Là encore, vous recevrez
un point x y
qui pourrait tomber n'importe
où dans le drapeau.
Et vous devez prendre une décision pour
renvoyer le bleu, le blanc ou le rouge.
Et lorsque vous faites cela,
assurez-vous d'utiliser
une construction if, else if, else.
これはフランスの国旗で
青、白、赤の3色になっています
この3色の幅を決める必要があります
左端の3分の1、真ん中そして右端です
Javaではまず最初の条件を実行します
あとで条件を埋める課題を出します
そして次のパートではif else文を使います
else ifと書いて次の条件を書くだけです
それ以外の場合についてはelse節を使います
従ってleft point とright pointという
2つの条件を入れる必要があります
ここが一番右端の部分だということも必要です
ここはif、else ifの条件で他の答えも入れられます
最後のelseは常に複数の判断を行っていて
上から下に順に実行していきます
最初の条件が満たされているかチェックして
命令が実行されれば他の条件はスキップされます
一方で最初の条件が
真でなければ次の条件をチェックして
それが真であれば実行します
もし真でなければ3番目を実行します
言い換えると3つのうちの1つは
条件を満たすかどうかによって確実に実行されます
ではフランスの国旗を作ってみてください
旗の中のどの位置にもxとyを配置できます
青、白、または赤の位置を決めなければなりません
if、else、else ifの条件を使うのも忘れずに
파란색, 흰색, 빨간색을 가지고 있는 프랑스의 국기입니다. 색이 3개니까
3개의 조건을 만들어야 합니다. 3등분한 부분 중에 자바는 어디서부터
시작할까요? 자바에서는 왼쪽에서 첫 번째로부터 시작합니다.
첫 번째 색은 if문으로 시작합니다. 프로그래밍은 여러분께 맡기겠습니다.
두 번째 부분은 else if문을 이용합니다.
그리고 마지막의 경우를 위해서 else문을 이용합니다.
총 3개의 조건이 있지만, 2개의 조건, 첫 번째와 두 번째 조건만
작성하시면 됩니다.
조건문 if를 작성하고 else if문을 이용하게 되면,
else문을 작성하기 이전에 else if 문을 원하는 만큼
이용할 수 있습니다. 여러분의 예상과 같이 if문에서 else문의
방향으로 프로그램은 실행됩니다. 첫 번째 조건인 if가 참이 돼서
실행이 되면, 나머지 조건문(else if, else)는 모두 건너뜁니다. 반면에,
만약 첫 번째 조건 if가 거짓이라면 다음 조건문으로 이동해서 참이면
실행이 되고 거짓이면 세 번째 조건을 실행시킵니다.
다른 말로 하자면, 3개의 색 중 하나는 꼭
색칠 된다는 말입니다.
이제 프랑스 국기를 색칠하러 가봅시다. 저번과 같이
여러분은 국기 안을 가리키는 x, y좌표를 이용해서
파란색, 흰색, 빨간색을 리턴할지 결정해야 합니다. 그래서
if, else if, else를 언제 사용해야 할지 잘 생각해야 합니다.
Đây là cờ nước Pháp với 3 màu xanh, trắng, đỏ. Nên ở đây,
có vẻ ta sẽ phải tạo 3 sự quyết định. Ta nên bắt đầu với phần đầu tiên,
phần giữa hay phần cuối? Trong Java bạn nên bắt đầu với điều kiện đầu tiên,
và tôi sẽ để bạn điền chi tiết vào trong bài tập.
Sau đó, với phần tiếp theo, bạn sẽ sử dụng mệnh đề else if,
nên bạn đơn giản chỉ viết else if theo sau là một điều kiện. Và cuối cùng, bạn dùng else cho khả năng còn lại.
Nên, ở đây bạn cần có 2 điều kiện, điểm đó ở bên trái?
điểm đó ở giữa? hoặc ngược lại? Tất nhiên, nó sẽ nằm ở phần bên phải.
Cấu trúc kiểu if, else if như này, bạn có thể có câu trả lời khác nếu bạn muốn.
Và cuối cùng, là lệnh else. Đây là cách bạn làm
mỗi khi bạn có nhiều sự lựa chọn. Và tôi đã làm từ trên xuống dưới như bạn mong đợi.
Điều kiện đầu tiên được dùng nếu nó thỏa mãn câu lệnh
được chạy trong này, và tất cả những cái khác được bỏ qua. Mặt khác,
nếu điều kiện đầu tiên không đúng, nó sẽ nhảy qua điều kiện thứ 2,
và nếu cái này đúng, thì đoạn lệnh này được chạy. Nếu không thì, cái thứ 3 sẽ được chạy.
Nói cách khác, chỉ có đúng 1 trong 3 đoạn lệnh này được chạy,
phụ thuộc vào điều kiện nào đúng hoặc không có cái nào đúng.
Giờ là lượt của bạn để thử sức với French flag. Một lần nữa,
bạn được cho 1 điểm x y có thể ở bất cứ đâu trong lá cờ.
Và bạn cần phải quyết định nó sẽ return value blue, white hay red. Và khi bạn làm thế,
hãy chắc chắn là bạn sử dụng cấu trúc if, else if, else.