Java常用API类之Math|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|Java常用API类之Math System tostring用法详解
文章图片

Java常用API类之Math|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|Java常用API类之Math System tostring用法详解
文章图片

Java常用API类之Math|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|Java常用API类之Math System tostring用法详解
文章图片

可以: Alt+insert(插入键(Insert key,缩写INS)是电脑键盘的一个键)
Java常用API类之Math|Java常用API类之Math System tostring用法详解
文章图片

选择toString()
Java常用API类之Math|Java常用API类之Math System tostring用法详解
文章图片

然后全选确认,自动生成
Java常用API类之Math|Java常用API类之Math System tostring用法详解
文章图片

【Java常用API类之Math|Java常用API类之Math System tostring用法详解】就Ok了
public class zi extends Object{int a=30; String we="我是说"; @Overridepublic String toString() {return "zi{" +"a=" + a +", we='" + we + '\'' +'}'; }public void show(){System.out.println("我是说"); }}

重新编译:得到
zi{a=30, we=‘我是说'} //明显
Java常用API类之Math|Java常用API类之Math System tostring用法详解
文章图片

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

    推荐阅读