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

3.个位数和

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

在这里插入图片描述


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.复利值

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

在这里插入图片描述


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.两点距离公式

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

在这里插入图片描述


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();

        double y2=s.nextDouble();

        //计算两点间距离

        double distance= sqrt(pow((x2-x1),2.0)+pow((y2-y1),2.0) );

        System.out.println("两点间距离为"+distance);

    }

}



[

必看视频!获取2024年最新Java开发全套学习资料 备注Java

]( )8.三角形面积

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

在这里插入图片描述


import java.util.Scanner;



import static java.lang.Math.pow;

import static java.lang.Math.sqrt;



public class Text8 {

    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();

        double y2=s.nextDouble();



        System.out.print("请输入x3,y3的值:");



# 1200页Java架构面试专题及答案

小编整理不易,对这份**1200页Java架构面试专题及答案**感兴趣劳烦帮忙**转发/点赞**

![](https://img-blog.csdnimg.cn/img_convert/172ba4a81a16a8ee08ecc1763af5e4ee.webp?x-oss-process=image/format,png)

![](https://img-blog.csdnimg.cn/img_convert/3f66f46989b907fed90c81fd9482b43f.webp?x-oss-process=image/format,png)

# 百度、字节、美团等大厂常见面试题

![](https://img-blog.csdnimg.cn/img_convert/384c9fac47dc92c637347c3061023bdf.webp?x-oss-process=image/format,png)

s.nextDouble();

        double y2=s.nextDouble();



        System.out.print("请输入x3,y3的值:");



# 1200页Java架构面试专题及答案

小编整理不易,对这份**1200页Java架构面试专题及答案**感兴趣劳烦帮忙**转发/点赞**

[外链图片转存中...(img-H4noqWx8-1716450641999)]

[外链图片转存中...(img-yr81hfAG-1716450642000)]

# 百度、字节、美团等大厂常见面试题

[外链图片转存中...(img-reRSz6Lr-1716450642001)]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值