import java.util.*;
import java.io.*; public class Loop { static Scanner console = new Scanner(System.in); public static void main(String[] args) { int i = 0;
int sum = 0; while ( console.hasNext() ) {
i = console.nextInt();
System.out.println(i);
sum = sum + i; } System.out.println("sum = " + sum); } }

这个代码,本来实验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.

Chapter 5 : Control Structures 2 : Repetition的更多相关文章

  1. Chapter 4 : Control Structures 1 : Selection

    Although it need not be, the expression is usually an identifier. Whether it is an identifieror an e ...

  2. 【Scala】Scala之Control Structures

    一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Structures Scala中的控制结构与Java中的颇 ...

  3. Python - 4. Control Structures

    From:http://interactivepython.org/courselib/static/pythonds/Introduction/ControlStructures.html Cont ...

  4. R Programming week2 Control Structures

    Control Structures Control structures in R allow you to control the flow of execution of the program ...

  5. Scala Control Structures

    Scala之Control Structures 一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Struc ...

  6. AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures

    10410 这题说的是给了一棵多叉树的 bfs遍历轨迹 和dfs 遍历 轨迹 在父节点向叶子节点扩展的时候优先遍历编号较小的节点.我还原出这课树特殊判定 根据bfs的顺序来建立这课树,用一个队列安排要 ...

  7. Scala入门指南与建议

    最近在学习使用Scala语言做项目,感觉这门语言实在是太优美了!作为一个本科数学.研究生机器学习专业的混合人才(哈哈),这门语言真的是满足了普通计算机编程(告诉计算机怎么做)和函数式编程(告诉计算机做 ...

  8. Core Java Volume I — 3.8. Control Flow

    3.8. Control FlowJava, like any programming language, supports both conditional statements and loops ...

  9. Methods and systems to control virtual machines

    Methods and systems are provided to control the execution of a virtual machine (VM). A VM Monitor (V ...

随机推荐

  1. node-RED

    node-RED提供了一个基于浏览器的编辑器,可以轻松地使用调色板中的广泛节点将流连接在一起,这些节点可以通过单击部署到其运行时.使用Node-RED,开发人员将输入/输出和处理节点连接起来,创建流程 ...

  2. 论文阅读笔记(七)YOLO

    You Only Look Once: Unified, Real-Time Object Detection Joseph Redmon, CVPR, 2016 1. 之前的目标检测工作将分类器用作 ...

  3. 第十七节,OpenCV(学习六)图像轮廓检测

    1.检测轮廓 轮廓检测是图像处理中经常用到的,OpenCV-Python接口中使用cv2.findContours()函数查找检测物体的轮廓. cv2.findContours(image, mode ...

  4. pysvn 相关

    sudo apt-get install python-svn sudo apt-get install svn-workbench 安装过程中如果缺少相关依赖下载好在执行这两条语句 安装好之后的界面 ...

  5. easyui,datagrid表格,行内可编辑

    最近用到easyui,需要表格内编辑,但是我同一个页面有多个表格,把官方的代码修改了一下,如下: HTML代码 <table id="dg" class="easy ...

  6. 如何在submit上运行php文件

    一..把php加入到环境变量 二.在sublmie中新建编译系统 三.添加一下代码,修改成php当前的目录地址,保存在默认的路径下,命名为php.sublime-build { "cmd&q ...

  7. 使用Mermaid画图

    流程图的示例 时序图的示例 甘特图的示例 FAQ 很多时候,你想解释自己的想法/代码,但是用语言来表达会很啰嗦,并且读者也不易理解.一般这种情况下,我们都会想使用图解来解释.但是,我们也不会想下载那些 ...

  8. MSYS 编译 nginx rtmp-module

    1. 下载源码 http://hg.nginx.org/nginx nginx-c74904a17021.zip https://github.com/arut/nginx-rtmp-module n ...

  9. Elastichsearch实践——基本使用

    官网文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/getting-started.html es中的索引.类型.文档可以 ...

  10. python学习记录20181220

    1.pycharm中,有个快捷键,输入完成后 按Ctrl+Alt+L就可以自动添加空格