zoukankan      html  css  js  c++  java
  • Chapter 5 : Control Structures 2 : Repetition

     1 import java.util.*;
     2 import java.io.*;
     3 
     4 public class Loop {
     5     
     6     static Scanner console = new Scanner(System.in);
     7     
     8     public static void main(String[] args) {
     9         
    10         int i = 0;
    11         int sum = 0;
    12         
    13         while ( console.hasNext() ) {
    14             i = console.nextInt();
    15             System.out.println(i);
    16             sum = sum + i;
    17     
    18         }
    19         
    20         System.out.println("sum = " + sum);
    21 
    22     }
    23 
    24 }
    View Code

      这个代码,本来实验while和console.hasNext(),不知错在哪里

    需要两次舒服EOF,  why????

    The break and continue statements are an effective way to avoid extra variables to control
    a loop and produce an elegant code. However, these statements must be used very sparingly
    within a loop. An excessive use of these statements in a loop will produce a spaghetti-code
    (loops with many exit conditions) and could be very hard to understand and manage.


    As stated earlier, all three loops have their place in Java and one loop can often replace
    another. The execution of a continue statement, however, is where a while structure
    differs from a for structure. In a while loop, when the continue statement is executed,
    if the update statement appears after the continue statement, the update
    statement is not executed. In a for loop, the update statement always executes.

  • 相关阅读:
    jenkins集成 Maven 构建工具
    CentOS 7.x 安装 Maven
    jenkins构建容器
    Jenkins常用插件
    jenkins插件加速
    抓包工具的前端性能测试技巧(fiddler)
    request中的POST类型及展示
    jmeter参数化处理json数据的注意事项
    jenkins+ant+jmeter在Linux下配置时的注意点
    jmeter中脚本数据分离并生成报告
  • 原文地址:https://www.cnblogs.com/hare/p/4105447.html
Copyright © 2011-2022 走看看