Movatterモバイル変換


[0]ホーム

URL:


Documentation

The Java™ Tutorials
Language Basics
Variables
Primitive Data Types
Arrays
Summary of Variables
Questions and Exercises
Operators
Assignment, Arithmetic, and Unary Operators
Equality, Relational, and Conditional Operators
Bitwise and Bit Shift Operators
Summary of Operators
Questions and Exercises
Expressions, Statements, and Blocks
Questions and Exercises
Control Flow Statements
The if-then and if-then-else Statements
The switch Statement
The while and do-while Statements
The for Statement
Branching Statements
Summary of Control Flow Statements
Questions and Exercises
Trail: Learning the Java Language
Lesson: Language Basics
Home Page >Learning the Java Language >Language Basics
« Previous • Trail • Next »

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
SeeDev.java for updated tutorials taking advantage of the latest releases.
SeeJava Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
SeeJDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.

Questions and Exercises: Control Flow Statements

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 thewhile statement, but evaluates its expression at the ___ of the loop.
  4. How do you write an infinite loop using thefor statement?
  5. How do you write an infinite loop using thewhile 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 ifaNumber is 3?
    2. Write a test program containing the previous code snippet; makeaNumber 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

« PreviousTrailNext »

About Oracle |Contact Us |Legal Notices |Terms of Use |Your Privacy Rights

Copyright © 1995, 2024 Oracle and/or its affiliates. All rights reserved.

Previous page: Summary of Control Flow Statements
Next page: Classes and Objects

[8]ページ先頭

©2009-2025 Movatter.jp