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. Exp5 MSF基础应用 20164314

    一.实践内容 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.一个主动攻击实践,如ms08_067; (成功) 2.一个针对浏览器的攻击,如ms1 ...

  2. MySQL学习11 - MySQL创建用户和授权

    权限管理 权限管理 我们知道我们的最高权限管理者是root用户,它拥有着最高的权限操作.包括select.update.delete.update.grant等操作.那么一般情况在公司之后DBA工程师 ...

  3. 文件的暂存(git add)

    如果我们更改了之前已经被跟踪的main.c,然后执行git status $ git status On branch master Changes not staged for commit: (u ...

  4. #20175204 张湲祯 2018-2019-2《Java程序设计》第六周学习总结

    20175204 张湲祯 2018-2019-2<Java程序设计>第六周学习总结 教材学习内容总结 -第七章内部类与异常类要点: 一.内部类: Java支持在一个类中定义另一个类,这样的 ...

  5. Input子系统(二)【转】

    转自:http://blog.chinaunix.net/uid-25047042-id-4192368.html 上一篇中粗略的分析了下input_dev,input_handle,input_ha ...

  6. javascript 常用方法 解析URL,补充前导字符

    2018-11-7 20:41:20 星期三 1. 解析URL function parseUrl(url){ url = decodeURIComponent(url); var u = url.s ...

  7. JAVA第三次实训作业

    ---恢复内容开始--- 1. 编写“学生”类及其测试类. “学生”类: 类名:Student 属性:姓名.性别.年龄.学号.5门课程的成绩 方法1:在控制台输出各个属性的值. 方法2:计算平均成绩 ...

  8. git branch 分支

    几乎所有的版本控制系统都以某种形式支持分支. 使用分支意味着你可以把你的工作从开发主线上分离开来,以免影响开发主线. 在很多版本控制系统中,这是一个略微低效的过程——常常需要完全创建一个源代码目录的副 ...

  9. md5两次加密

    private static final String salt="hzjfstkfdff"; public static String MD5(String src) { ret ...

  10. C++中的const总结

    CONST 一.符号常量 声明: const 类型说明符 常量名 = 常量值: const float PI = 3.1415927; //可以交换const与float的位置 符号常量在声明时一定要 ...