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 }

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

时间: 2024-10-12 04:57:38

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

Chapter 4 : Control Structures 1 : Selection

Although it need not be, the expression is usually an identifier. Whether it is an identifieror an expression, the value of the identifier or the expression can only be of type int, byte, short,or char. public class StringComapre { public static void

Scala Control Structures

Scala之Control Structures 一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Structures Scala中的控制结构与Java中的颇为类似,但也有所不同,例如,if/then/else控制结构与Java的类似,但是其可以返回值,虽然Java中有三元运算符的特殊语法,但是在Scala中使用if就可以达到同样的效果. val x = if (a) y else z 同样,Scala的

【Scala】Scala之Control Structures

一.前言 前面学习了Scala的Numbers,接着学习Scala的Control Structures(控制结构). 二.Control Structures Scala中的控制结构与Java中的颇为类似,但也有所不同,例如,if/then/else控制结构与Java的类似,但是其可以返回值,虽然Java中有三元运算符的特殊语法,但是在Scala中使用if就可以达到同样的效果. val x = if (a) y else z 同样,Scala的try/catch/finally 结构与Java

R Programming week2 Control Structures

Control Structures Control structures in R allow you to control the flow of execution of the program, depending on runtime conditions. Common structures are: if, else: testing a condition for: execute a loop a fixed number of times while: execute a l

Methods and systems to control virtual machines

Methods and systems are provided to control the execution of a virtual machine (VM). A VM Monitor (VMM) accesses VM Control Structures (VMCS) indirectly through access instructions passed to a processor. In one embodiment, the access instructions inc

A GUIDE TO UNDERSTANDINGDISCRETIONARY ACCESS CONTROL INTRUSTED SYSTEMS

1. INTRODUCTION ? The main goal of the National Computer Security Center is to encourage the widespread availability of trusted computer systems. In support of that goal a metric was created, the Department of Defense Trusted Computer System Evaluati

C++ Core Guidelines

C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very early draft. It is inkorrekt, incompleat, and pµøoorly formatted. Had it been an open source (code) project, this would have been release 0.6. Copy

linux c coding style

Linux kernel coding style This is a short document describing the preferred coding style for the linux kernel. Coding style is very personal, and I won't _force_ my views on anybody, but this is what goes for anything that I have to be able to mainta

《R in Nutshell》 读书笔记(连载)

R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshell") 第一部分:基础 第一章 批处理(Batch Mode) R provides a way to run a large set of commands in sequence and save the results to a file. 以batch mode运行R的一种方式是:使用系统