首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
执行以下的循环后输出的值为( )。 public class Sun { public static void main (String args[ ]) { int m=1000, s=0,
执行以下的循环后输出的值为( )。 public class Sun { public static void main (String args[ ]) { int m=1000, s=0,
admin
2010-07-28
44
问题
执行以下的循环后输出的值为( )。 public class Sun { public static void main (String args[ ]) { int m=1000, s=0, n=0; do{ n=n+l; s=s+(int)Math.pow(2,n); }while (s<=m); System.out.println("n="+n+","+"s="+s); } }
选项
A、n=9, s=1000
B、n=8, s=1022
C、n=9, s=1022
D、n=8, s=1000
答案
4
解析
本题考查对do-while循环的理解。本题完成的功能是求当20+21+22+...+2n最少需要多少项时才能满足大于数值m。 m=1000,当程序运行到第8次时,循环测试条件仍然为真,所以继续执行1次,当执行到第 9次时,s的值已经超过了1000。故本题答案是C。
转载请注明原文地址:https://kaotiyun.com/show/oR9p777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
某二叉树共有12个结点,其中叶子结点只有1个。则该二叉树的深度为(根结点在第1层)
按照“后进先出”原则组织数据的数据结构是
下列叙述中正确的是
下面不属于需求分析阶段任务的是
下列选项中不属于软件生命周期开发阶段任务的是
下列描述中错误的是
下列描述中错误的是
设一年365天,第1天的能力值为基数记为1.0。当好好学习时能力值相比前一天会提高千分之五。以下选项中,不能获得持续努力1年后的能力值的是
下面关于Python中函数的说法错误的是()。
当输入一个字节流时,要______。
随机试题
下列选项中,关于紧急避险与正当防卫的说法,错误的是()。
下列哪项不是胸外心脏按压的有效标志()
根据《城市用地竖向规划规范》(CJJ83—1999)的规定,下列关于城市道路广场竖向规划的基本要求表述正确的是().
出口口岸()件数()
物业经营管理活动的管理对象通常为()。
Thecoachexplainedtheregulationsatlengthtomakesurethatnoneofhisplayerswouldbecomeviolators.
AwaronsugarhasbegunintheUKthatechoesthenation’ssuccessfulcampaignagainstsalt.Theeffortis【C1】______becauseit
Itisdifficultfornearlyeveryfamilytoteachtheirchildrentoberesponsiblefor(对......负责)housework,butwithoneofthefo
HenryDavidThoreau—WhyIWenttotheWoodsLetusspendonedayasdeliberatelyasNature,andnotbethrownoffthetrack
Theageofrequiringretirementincompaniesshouldberaised,andso【M1】______shouldtheagetobeginSocialSecurity.First
最新回复
(
0
)