java 面试每日一题
题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
import java.util.Scanner;
public class testOne {
/**
* @param args
*/
private double totalHeight=100;
private double curHeight=50;
//下落
public void drop(int times){
if((times-1)==0){
return ;
}
setTotalHeight(getTotalHeight()+2*getCurHeight());
setCurHeight(getCurHeight()/2);
drop(times-1);
}
private void setCurHeight(double CurHeight) {
curHeight=CurHeight;
}
public void setTotalHeight(double TotalHeight) {
totalHeight=TotalHeight;
}
public double getCurHeight() {
return curHeight;
}
public double getTotalHeight() {
return totalHeight;
}
public static void main(String[] args) {
System.out.println("请输入次数:");
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
testOne main=new testOne();
main.drop(i);
System.out.println("总高度是"+main.getTotalHeight());
System.out.println("最后一次反弹高度是"+main.getCurHeight());
}
}
java 面试每日一题的更多相关文章
- java面试每日一题8
题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...
- java 面试每日一题6
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5 ...
- java面试每日一题5
题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提 成,高于10万元的部分,可可提成7.5%:20万到40 ...
- java 面试每日一题3
题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字.例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制. import java.io.Bu ...
- java 面试每日一题2
题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. 注:如果想单独输出中文的个数和中文符号的个数,只需把isChinese()中的if语句修改 知识补充: java不像C中拥有s ...
- java面试每日一题13
题目:有一个分数数列2/1.3/2.5/3.8/5.13/8........求出这个数列的前20项之和.运行结果如下32.660263 public class Page80 { /** * * @p ...
- java面试每日一题12
题目:打印出如下图案(菱形) * *** ****** ******** ****** *** * public class Diamond { public static ...
- java面试每日一题11
题目:求1+2!+3!+...+20!的和 public class Recursion { public static void main(String args[]) throws NumberF ...
- java面试每日一题10
题目:利用递归方法求5! public class Recursion { public static void main(String args[]) throws NumberFormatExce ...
随机推荐
- ThinkPHP分页链接支持数组参数的办法
这几天在用ThinkPHP做系统,搜索页有个数组参数提交 <input class="params_t" name="t[]" type="ch ...
- log4j2.x 配置文件默认寻找顺序
Automatic Configuration Log4j has the ability to automatically configure itself during initializatio ...
- Function call process
摘自自博客网址 http://www.cnblogs.com/bangerlee/archive/2012/05/22/2508772.html ax(accumulator): 可用于存放函数返回值 ...
- stack note
参考 http://www.cnblogs.com/java06/archive/2012/10/16/3122428.html 1,顺序栈 定义栈: #define stacksize 1000; ...
- Lintcode: Search Range in Binary Search Tree
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all t ...
- Summary: Trie Data Structure
Implement a Trie Data Structure, and search() & insert() function: we need to implement both Cla ...
- :“boost/serialization/string.hpp”: No such file or directory 错误
主要原因是没有安装和配置boost库. 解决:http://www.programlife.net/boost-compile-and-config.html
- Codeforce Round #224 Div2
一下子没打,这比赛,就被虐成狗!
- 压缩 & 解压缩 命令汇总:tar、zip & unzip、
1. tar命令详解 格式:tar [-cxtzjvfpPN] 文件与目录 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...
- android studio ADB not responding.
打开cmd 输入 netstat -aon|findstr "5037" 找到谁在占用5037端口 记住他的pid. 例如pid为 2028 输入 taskkill ...