7-16 学投资
单位 山东科技大学
小白学习了一些复利投资知识,想比较一下复利能多赚多少钱(所谓复利投资,是指每年投资的本金是上一年的本金加收益。而非复利投资是指每年投资金额不包含上一年的收益,即固定投资额)。假设他每年固定投资M元(整数),每年的年收益达到P(0<P<1,double),那么经过N(整数)年后,复利投资比非复利投资多收入多赚多少钱呢?计算过程使用双精度浮点数,最后结果四舍五入输出整数(Math的round函数)。
输入格式:
M P N
输出格式:
复利收入(含本金),非复利收入(含本金),复利比非复利收入多的部分(全部取整,四舍五入)
样例">输入样例:
10000 0.2 3
输出样例:
17280 16000 1280
答案:
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args)
{
Scanner reader=new Scanner(System.in);
while(reader.hasNext())
{
double a= reader.nextDouble();
double b= reader.nextDouble();
double c= reader.nextDouble();
double p;
double x=a+a*b*c;
for(int i=0;i<c;i++)
{
p=a*b;
a=a+p;
}
System.out.print(Math.round(a)+" "+Math.round(x)+" "+Math.round(a-x));
}
reader.close();
}
}
7-17 Reversed 3-Digit-Number
单位 浙江大学
Your program reads a positive 3-digit-number in and prints the digits in reversed order. There should not be any leading zeros when the number has tailing zeros. For example, the output should be 7 for the number 7000.
Input Format:
A postive 3-digit-number.
Output Format:
A reversed number.
Sample Input:
123
Sample Output:
321
答案:
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args)
{
Scanner reader=new Scanner(System.in);
int a= reader.nextInt();
int x,y,z,b;
if(99<a&1000>a)
{
x=a/100;
y=a/10%10;
z=a%10;
b=z*100+y*10+x;
System.out.println(b);
}
}
}
7-11 计算钱币
分数 10
全屏浏览题目
切换布局
作者 殷伟凤
单位 浙江传媒学院
编写程序,读取用户输入的代表总金额的double值,打印表示该金额所需的最少纸币张数和硬币个数,打印从最大金额开始。纸币的种类有十元、五元、一元,硬币的种类有五角、一角、贰分、壹分。
输入格式:
47.63
输出格式:
4 张十元
1 张五元
2 张一元
1 个五角
1 个一角
1 个贰分
1 个壹分
输入样例:
在这里给出一组输入。例如:
47.63
输出样例:
在这里给出相应的输出。例如:
4 张十元
1 张五元
2 张一元
1 个五角
1 个一角
1 个贰分
1 个壹分
答案:
import java.util.Scanner;
import java.lang.Math;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args)
{
Scanner reader=new Scanner(System.in);
double x= reader.nextDouble();
int a=(int)x/10;
int b=(int)(x-a*10)/5;
int c=(int)(x-a*10)%5;
int d=(int)(x*10%10/5);
int e=(int)(x*10%10%5);
int f=(int)(x*100%10)/2;
int g=(int)(x*100%10)%2;
System.out.println(a+" 张十元");
System.out.println(b+" 张五元");
System.out.println(c+" 张一元");
System.out.println(d+" 个五角");
System.out.println(e+" 个一角");
System.out.println(f+" 个贰分");
System.out.println(g+" 个壹分");
}
}