Algorithms(4th Edition),Java Programming Model

Statements.

 A Java program is composed of  statements , which define the computation by creating and manipulating variables, assigning data-type values to them, and controlling the flow of execution of such operations.
  • Declarations create variables of a specified type and name them with identifiers. Java is a strongly typed language because the Java compiler checks for consistency. The scope of a variable is the part of the program where it is defined.

  • Assignments associate a data-type value (defined by an expression) with a variable.

  • Initializing declarations combine a declaration with an assignment to initialize a variable at the same time it is declared.

  • Implicit assignments. The following shortcuts are available when our purpose is to modify a variable's value relative to the current value:
    • Increment/decrement operators: the code i++ is shorthand for i = i + 1. The code ++i is the same except that the expression value is taken after the increment/decrement, not before.

    • Other compound operators: the code i /= 2 is shorthand for i = i/2.

  • Conditionals provide for a simple change in the flow of execution—execute the statements in one of two blocks, depending on a specified condition.

  • Loops provide for a more profound change in the flow of execution—execute the statements in a block as long as a given condition is true. We refer to the statements in the block in a loop as the body of the loop.

  • Break and continue. Java supports two additional statements for use within while loops:
    • The break statement, which immediately exits the loop

    • The continue statement, which immediately begins the next iteration of the loop

  • For notation. Many loops follow this scheme: initialize an index variable to some value and then use a while loop to test a loop continuation condition involving the index variable, where the last statement in the while loop increments the index variable. You can express such loops compactly with Java's for notation.

  • Single-statement blocks. If a block of statements in a conditional or a loop has only a single statement, the curly braces may be omitted.
Java statements

Input and output.
  • Commands and arguments.

    anatomy of a command

  • Standard output.

  • Formatted output.

    printf formatting conventions

  • Standard input.

  • Redirection and piping.

    redirection and piping from the command line

  • Input and output from a file.

  • Standard drawing.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值