java经典编程笔试题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
题目1:一个球从100米高度自由落下,每次落地后反跳回原高度的一半;在落下,求它在第10次落地时,共经过多少米?第十次反弹多高?
如果把double类型换成int类型定义你认为它共经过多少米
反弹高度又会是多少?
public static void main(String[] args) {
double h = 100,s = 100;
for(int i=1; i<10; i++) {
s = s + h;
h = h / 2;
}
System.out.println("经过路程:" + s);
System.out.println("反弹高度:" + h / 2);
}
题目2:有1、2、3、4个数字,能组成多少个相同且无重复数字的三位数
public static void main(String[] args) {
int a = 0;
for(int x=1; x<5; x++) {
for(int y=1; y<5; y++) {
for(int z=1; z<5; z++) {
if(x != y && y != z && x != z) {
a ++;
System.out.println(x*100 + y*10 + z );
}
}
}
}
System.out.println(a);
}
题目3:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
public static void main(String[] args) {
for (int x = 1; x < 100000; x++) {
if (Math.sqrt(x + 100) % 1 == 0) {
if (Math.sqrt(x + 268) % 1 == 0) {
System.out.println(x);
}
}
}
}
題目4:下面代码输出结果是什么?
package test;
public class Test{
public static void main(String[] args){ double val =11.5;
System.err.println(Math.round(val));
System.err.println(Math.floor(val));
System.err.println(Math.ceil(val));
}
}