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. TortoiseSVN新人使用指南

    http://blog.csdn.net/maplejaw_/article/details/52874348

  2. java(11)带参数的方法

    一.java中的包(package) 1.1 包,对应到磁盘中的文件夹 1.2 新建一个class,默认保存在缺省包中 1.3 声明包的关键字:package package语句,置顶位置 1.4 导 ...

  3. neo4j语法

    图数据库在社交网络.实时推荐.征信系统.人工智能等领域有广泛应用. 集群特征:主从复制,重选主服务器和容错:每个实例都有自己的本地缓冲 性能优势:查询内不跨网络:实时操作,具有快速和一致的响应时间:缓 ...

  4. 安装hue及hadoop和hive整合

    环境: centos7 jdk1.8.0_111 Hadoop 2.7.3 Hive1.2.2 hue-3.10.0 Hue安装: 1.下载hue-3.10.0.tgz: https://dl.dro ...

  5. ViewPager刷新原理

    ViewPager的数据是通过PageAdapter来装载的,刷新数据的方法有以下: 调用adapter.notifyDataSetChanged(); 刷新控件,但是要覆盖PagerAdapter的 ...

  6. 在可编辑div的光标下插入html

    function pasteHtmlAtCaret(html, selectPastedContent) {//参数1为要插入的html //参数2为boolean 是否选中插入的html 默认为fa ...

  7. JavaScript—var lef const区别

    今天刚刚学JavaScript 因为以前学过.学起来也就轻松.今天在练习.流程控制语句的时候,用WebStrom 写的时候 var 声明变量的时候 下面老是有一条白线.开始以为是开发环境有问题 然后, ...

  8. 第十六节,OpenCV(学习五)边缘检测

    边缘检测 边缘检测的目的是标识数字图像中亮度变化明显的点,边缘检测是特征提取的重要领域. 1.检测方法 边缘检测的方法大致分为两类:基于搜索和基于零交叉 基于搜索的边缘检测方法首先计算边缘强度,通常用 ...

  9. Maven - 本地仓库(.m2) vs. 远程仓库(联网)

    转载自:https://www.cnblogs.com/shuaiandjun/p/7604619.html 什么是Maven仓库在不用Maven的时候,比如说以前我们用Ant构建项目,在项目目录下, ...

  10. python学习第37天

    MySQL数据库 数据库的优势 什么是数据(Data) 什么是数据库(DataBase,简称DB) 什么是数据库管理系统(DataBase Managerment System 简称DBMS) 数据库 ...