• 使用标记值控制循环:sum,data


    使用标记值控制循环:sum,data

     1 package com.baidu;
     2 import java.util.Scanner;
     3 public class SentinelValue {
     4     public static void main(String[] args) {
     5         Scanner input = new Scanner(System.in);//(Input):只能从中读取数据,而不能向其写入数据
     6         
     7         System.out.print("Enter an unteger (the input ends if it is 0 ): ");
     8         int data = input.nextInt();//(Input):只能从中读取数据,而不能向其写入数据
     9         
    10         int sum = 0;
    11         while(data != 0) {
    12             sum += data;
    13             
    14             System.out.print("Enter an integer (the input ends if it is 0): ");
    15             data = input.nextInt();//(Input):只能从中读取数据,而不能向其写入数据
    16         }
    17         System.out.println("The sum is " + sum);
    18     }
    19 }

    This moment will nap, you will have a dream; but this moment study, you will interpret a dream.
  • 相关阅读:
    NOIP2020 游记
    李超线段树
    选举「elections」
    Alt+数字输入
    素数
    CSP-S2020 爆炸记
    [CF487C] Prefix Product Sequence
    [CF489E] Hiking
    L2-019 悄悄关注 (25 分)
    L2-032 彩虹瓶 (25 分)
  • 原文地址:https://www.cnblogs.com/mawenqi-barry/p/7744348.html
Copyright © 2020-2023  润新知