首页 > 代码库 > Chapter 5 : Control Structures 2 : Repetition

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(),不知错在哪里

Chapter 5 : Control Structures 2 : Repetition