2021级-JAVA02 基础语法1--标识符、常量与变量、数据类型、运算符与表达式209 天

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+" 个壹分");
    }
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值