千家信息网

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

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇内容介绍了"Java常用API类之如何使用Math System tostring"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!
千家信息网最后更新 2025年02月04日Java常用API类之如何使用Math System tostring

本篇内容介绍了"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));    }}

结果:

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)+"多少毫秒");}}

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

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

选择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类内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

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

0