博客
关于我
2016蓝桥杯javaB组
阅读量:676 次
发布时间:2019-03-16

本文共 892 字,大约阅读时间需要 2 分钟。

一、煤球数目

1.题目:

有一堆煤球,堆成三角棱锥形。具体:

第一层放1个,
第二层3个(排列成三角形),
第三层6个(排列成三角形),
第四层10个(排列成三角形),
如果一共有100层,共有多少个煤球?

请填表示煤球总数目的数字。    注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
2.解答:
public class seven1 {       public static void main(String[] args) {           int sum =1;        int l = 1;        for (int i = 2;i<=100;i++){               l=l+i;            sum=sum+l;        }        System.out.println(sum);    }}
3.答案:

在这里插入图片描述

二、生日蜡烛

1.题目:
某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛。    现在算起来,他一共吹熄了236根蜡烛。    请问,他从多少岁开始过生日party的?    请填写他开始过生日party的年龄数。    注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
2.解答:
public class seven2 {       public static void main(String[] args) {           for(int i=1;i<=100;i++){               int sum = 0;            for(int j=i;j<=100;j++){                   sum=sum+j;                if(sum ==236){                       System.out.println(i);                }            }        }    }}
3.答案:

在这里插入图片描述

转载地址:http://nrtqz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>