본문 바로가기
Java 배우기

Questions and Exercises: Control Flow Statements

by 노화방지 Anti-aging Hairstyle 2016. 1. 5.
반응형

Questions

  1. The most basic control flow statement supported by the Java programming language is the ___ statement.
  2. The ___ statement allows for any number of possible execution paths.
  3. The ___ statement is similar to the while statement, but evaluates its expression at the ___ of the loop.
  4. How do you write an infinite loop using the for statement?
  5. How do you write an infinite loop using the while statement?

Exercises

  1. Consider the following code snippet.

    if (aNumber >= 0)
        if (aNumber == 0)
            System.out.println("first string");
    else System.out.println("second string");
    System.out.println("third string");
    
    1. What output do you think the code will produce if aNumber is 3?
    2. Write a test program containing the previous code snippet; make aNumber 3. What is the output of the program? Is it what you predicted? Explain why the output is what it is; in other words, what is the control flow for the code snippet?
    3. Using only spaces and line breaks, reformat the code snippet to make the control flow easier to understand.
    4. Use braces, { and }, to further clarify the code.

Check your answers


반응형

'Java 배우기' 카테고리의 다른 글

Classes 클래스  (0) 2016.01.05
Lesson: Classes and Objects 단원: 클래스와 객체  (0) 2016.01.05
Summary of Control Flow Statements  (0) 2016.01.05
Branching Statements  (0) 2016.01.05
The for Statement  (0) 2016.01.05

댓글