温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Java常用API类之如何使用Math System tostring

发布时间:2021-10-25 14:54:28 来源:亿速云 阅读:134 作者:iii 栏目:开发技术

本篇内容介绍了“Java常用API类之如何使用Math System tostring”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

1.注意(类名不能与math重名,否则可能报错误)

1.math:可以直接拿来用的接口类

Math.abs(-90);返回参数的绝对值
Math.max(60,98)返回参数的最大值
Math.random()*100随机函数:随机输出一个数
等等

public static void main(String[] args){
        
        int a = 1300, b = 1000;
        System.out.println(Math.abs(-90));
        System.out.println(Math.max(60,98));
System.out.println(Math.random()*100);

        System.out.println(Math.ceil(b));


    }}

结果:

Java常用API类之如何使用Math System tostring

Java常用API类之如何使用Math System tostring

2.System的API:

System.exit(0);// 在这个API下的往下内容java代码会停止执行
System.currentTimeMillis();//返回与从1970年到现在的毫秒数

public class tyue {



    public static void main(String[] args){


        System.out.println("开始!");

        //System.exit(0);
        System.out.println("结束!");

        System.out.println(System.currentTimeMillis()*1/1000/60/60/24/365+"年");

Long begin=System.currentTimeMillis();
for(int i=0;i<=1000;i++)
{
System.out.println(i);


    }
Long end=System.currentTimeMillis();
System.out.println("共耗时"+(end-begin)+"多少毫秒");



}}

Java常用API类之如何使用Math System tostring

Java常用API类之如何使用Math System tostring

3.object类中的:tostring()方法

如果:直接怎么写:

zi sc=new zi();

System.out.println(sc);

System.out.println(sc.toString());

打印出:zi@1b6d3586;这样不易观察
可以通过:
println
Ctrl+B: 打开方法的声明处点击print(这个System.out.println(sc))
可以看到:

public class zi extends Object{

int a=30;
String we="我是说";

    public void show(){


    System.out.println("我是说");

}

}
public static void main(String[] args){

      zi sc=new zi();


      System.out.println(sc);
        System.out.println(sc.toString());
//public void println(Object x) {
//        String s = String.valueOf(x);
//        synchronized (this) {
//            print(s);
//            newLine();
//        }
//    }                 //方法的声明处  ctrl+b
        /*public static String valueOf(Object obj) {
            return (obj == null) ? "null" : obj.toString();
        }

*/
      sc.show();




    }

Java常用API类之如何使用Math System tostring

可以: Alt+insert(插入键(Insert key,缩写INS)是电脑键盘的一个键)

Java常用API类之如何使用Math System tostring

选择toString()

Java常用API类之如何使用Math System tostring

然后全选确认,自动生成

Java常用API类之如何使用Math System tostring

就Ok了

public class zi extends Object{

int a=30;
String we="我是说";


    @Override
    public String toString() {
        return "zi{" +
                "a=" + a +
                ", we='" + we + '\'' +
                '}';
    }

    public void show(){


    System.out.println("我是说");

}

}

重新编译:得到
zi{a=30, we=‘我是说'} //明显

Java常用API类之如何使用Math System tostring

到此这篇关于Java常用API类之Math System tostring用法详解的文章就介绍到这了,更多相关Java 常用API类内容请搜索亿速云以前的文章或继续浏览下面的相关文章希望大家以后多多支持亿速云!

“Java常用API类之如何使用Math System tostring”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI