首页 \ 问答 \ 数据库系统的组成

数据库系统的组成

A数据库 B硬件和软件 C数据库管理员 D以上都是
更新时间:2023-10-26 21:10

最满意答案

int sum=0;

for(int i=1;i<=100;i++){

    sum+=i;

}

//sum初始化是0,sum+=i;   ---->    sum=sum+i;    每执行一次循环sum就等于上一次循环中sum的值再加上i

//所以最后的结果是从1加到100的和

 

int  sum=0

for(int i=1;i<=100;i++){

    y=sum+i

}

//sum初始化为0,y初始化应该也是0吧,  y=sum+i;   因为sum的值在循环中根本就没有被改变过,每执行完一个循环,y的值就等于0加上前一次循环中 i 的值,所以最后结果就是 y=0 + 100,当然,如果改成这样:y+=sum+i,这样又不同了......

其他回答

sum+=i;  是累加啊 sum=sum+1
你的 y=sum+i,sum 一直是0啊 ,当人最后是100了
sum+=i;相当 于sum=sum+i; 每次sum的值,都 变,所以 才会累加 。

for(int i=1;i<=100;i++){

    y=sum+i

朋友你看sum=sum+i(sum+=i),和y=sum+i,有什么区别 你定义的i在变,可是你定义的sum没变,程序只会根据i的变化把值赋给y,而你的i最大就是100,所以程序的结果只是执行了i++而已直到不满足条件,并没有实现for循环每一次结果也就是sum的累加,如果还是不清楚就把i的值带进去,慢慢体会,会明白的。

相关问答

更多
  • 分支结构:if-then-else语句、while语句、for语句、switch语句控制Java程序的流程,能够在最合适使用的时候,使用它们。并且知道它们与其它程序设计语言的流程控制之间的不同。
  • 这。。。上课要好好听啊 这就是程序的运行先后顺序问题了 这个用文字实在不好表达 先说第二个图 首先。进for循环 首先判断for的条件是否满足 第一次: 当i=1时 条件满足 则进入for程序中 判断if条件: 第一个if不满足 直接 跳过 第二次:。i=2.。。。。。。。。。。。。。。。。。。。。 。。。。。。。。。。。。。。。。。。。 第30次 i=30 。。。 满足第一个if条件 进入其中 : 先输出 30 然后count++ 即count=1 判断第二个if条件: 不满足 跳过 继续开始for 这样 ...
  • WHILE 条件 DO 循环体 END WHILE;
  • int sum=0; for(int i=1;i<=100;i++){ sum+=i; } //sum初始化是0,sum+=i; ----> sum=sum+i; 每执行一次循环sum就等于上一次循环中sum的值再加上i //所以最后的结果是从1加到100的和 int sum=0 for(int i=1;i<=100;i++){ y=sum+i } //sum初始化为0,y初始化应该也是0吧, y=sum+i; 因为sum的值在循环中根本就没有被改变过,每执行完一个循环,y的值就等于0加上前一次循环中 i ...
  • for有很多种用法: 1. 表示“当作、作为”。如: I like some bread and milk for breakfast. 我喜欢把面包和牛奶作为早餐。 What will we have for supper? 我们晚餐吃什么? 2. 表示理由或原因,意为“因为、由于”。如: Thank you for helping me with my English. 谢谢你帮我学习英语。 Thank you for your last letter. 谢谢你上次的来信。 Thank you for ...
  • 1 For循环是计次数循环,循环次数由循环变量的终值减去初值再除以步长。 2 Do While是条件循环,当循环条件为真时循环,这样就有可能一次也不执行循环体,循环体内必有一条让条件由真变假的语句,为结束循环做准备。
  • 尝试 if ($item->date >= $start_date && $item->date <= $end_date) { // … 否则,第二个条件不完整。 try if ($item->date >= $start_date && $item->date <= $end_date) { // … Otherwise, the second condition is incomplete.
  • 使用像你建议的一系列4个三元运算符并不是一个好主意,因为它有点难以阅读。 如果您担心的是代码行数,您可以使用以下方法缩短方法: public static boolean isPrime(int n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; double sqrtN = Math.sqrt(n); for (int i = 3; i <= sqrtN; i += 2) { if (n % i ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)