Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 10', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | PREV NEXT Page 221 Summary The for repetition statement specifies the details of counter-controlled-repetition. The general format of the for statement is for initialization loopContinuationCondition increment statement where the initialization expression names the loop s control variable and provides its initial value loopContinuationCondition is the condition that determines whether the loop should continue executing and increment modifies the control variable s value so that the loopcontinuation condition eventually becomes false. Typically for statements are used for counter-controlled repetition and while statements are used for sentinel-controlled repetition. Page 222 The scope of a variable defines where it can be used in a program. For example a local variable can be used only in the method that declares the variable and only from the point of declaration through the end of the method. The initialization loop-continuation condition and increment portions of a for statement can contain arithmetic expressions. The increment of a for statement may also be negative in which case it is really a decrement and the loop counts downward. If the loop-continuation condition in a for header is initially false the program does not execute the for statement s body. Instead execution proceeds with the statement following the for. The format specifier 20s outputs a string with a field width of 20 . at least 20 character positions . If the value to be output is less than 20 character positions wide the value is right justified in the field by default. A value can be output left justified by simply preceding the field width with the minus sign formatting flag. Methods that perform common tasks and do not require objects are called static methods. Java does not include an exponentiation operator. Instead x y can be used to calculate the value of x raised to the y th power. The method receives two double arguments and returns a double value. The comma formatting .