JavaSE篇学习之路:(二)【小试牛刀】

}

}




[]( )2.计算小费

===================================================================



![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105153642.png)



import java.util.Scanner;

public class Text2 {

public static void main(String[] args) {

    System.out.print("请输入一笔费用和酬金率:");

    Scanner s=new Scanner(System.in);

    //读入费用

    double tips=s.nextDouble();

    //读入酬金率

    double rate=s.nextDouble();

    //计算酬金

    double Remuneration=(tips*rate)/100+(tips*rate)%10;//计算酬金

    //计算总费用

    double cost=tips+Remuneration;

    System.out.println("酬金为:"+Remuneration+"\t"+"总费用为:"+cost);

}

}




[]( )3.个位数和

===================================================================



![在这里插入图片描述](https://img-blog.csdnimg.cn/202006111053228.png)



import java.util.Scanner;

public class Text3 {

public static void main(String[] args) {

    System.out.println("请输入一个0~1000的数字:");

    Scanner s = new Scanner(System.in);

    int i = s.nextInt();

    if (i > 0 && i < 1000) {

        //取百位

        int x=i/100;

        //取十位

        int y=i/100%10;

        //取个位

        int z=i%10;

        System.out.println("个位数相加和为:"+x+y+z);

    }else{

        System.out.println("对不起,您输入的数字有误!");

    }

}

}




[]( )4.复利值

==================================================================



![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105404362.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1pwX2luc2lzdA==,size_16,color_FFFFFF,t_70)



import java.util.Scanner;

public class Text4 {

public static void main(String[] args) {

    System.out.println("请输入存入的金额以及要查询余额月份:");

    Scanner s=new Scanner(System.in);

    int dollar=s.nextInt();

    int month=s.nextInt();

    double cost=0.0;



    for(int i=1;i<=month;i++){

        cost=(dollar+cost)*(1+0.00417);

        System.out.println("第"+i+"个月后帐户的金额为:"+cost);

    }

}

}




[]( )5.实现二进制转化十进制

=========================================================================



import java.util.Scanner;

public class Text5 {

public static void main(String[] args) {

    Scanner s=new Scanner(System.in);

    System.out.print("输入一个二进制数 ");

    int binaryNumber = s.nextInt();

    int decimal = 0;

    int p = 0;

    while (true) {

        if (binaryNumber == 0) {

            break;

        } else {

            int temp = binaryNumber % 10;

            decimal += temp * Math.pow(2, p);

            binaryNumber = binaryNumber / 10;

            p++;

        }

    }

    System.out.println("十进制数为:"+decimal);

}

}




[]( )6.实现十进制转化二进制

=========================================================================



import java.util.Scanner;

public class Text6 {

public static void main(String[] args) {

    Scanner s=new Scanner(System.in);

    System.out.print("输入一个十进制数 ");

    int n = s.nextInt();

    String str = "";

    while (n != 0) {

        str = n % 2 + str;

        n = n / 2;

    }

    System.out.println(str);

}

}




[]( )7.两点距离公式

=====================================================================



![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105638696.png)



import java.util.Scanner;

import static java.lang.Math.*;

public class Text7 {

public static void main(String[] args) {

    System.out.print("请输入x1,y1的值:");

    Scanner s=new Scanner(System.in);

    double x1=s.nextDouble();

    double y1=s.nextDouble();

    System.out.print("请输入x2,y2的值:");

    double x2=s.nextDouble();
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值