一,Java顶级对象之Object对象-面试题
package chapter14;
public class ObjectTest {
public static void main(String [] args){
Class clazz=new ObjectTest().getClass();//每一个类也是其他类的一个对象
System.out.println(clazz.getName());
}
}
二,Java基本数学运算之Math类详解
package chapter14;
public class MathText {
public static void main(String [] args){
//计算平方根
System.out.println(Math.sqrt(16));
//计算立方根
System.out.println(Math.cbrt(8));
//两个数的最大值,支持int,double,float,long
System.out.println(Math.max(124,46547));
System.out.println(Math.min(12.3,32.66));
//ceil向上取整,更大的值靠拢,中文是天花板
System.out.println(Math.ceil(-32.4));
System.out.println(Math.ceil(12.34));
//floor向下取整,更小的值靠拢,中文是地板
System.out.println(Math.floor(-32.4));
System.out.println(Math.floor(12.34));
//随机数,大于等于0小于1的double类型的数
System.out.println(Math.random());
//产生1-10的随机数,int方法进行转换,去掉小数点后面的部分。不会四舍五入
for(int i= 0;i<10;i++){
int random=(int)(Math.random()*10+1);//不加1的结果0,1,2,3,4,5,6,7,8,9
System.out.println(random);
}
}
}
三,Java核⼼心字符串串String进阶
package chapter14;
public class StringTest {
public static void main(String [] args){
// String str1=new String("xdclass.com");
// String str2="xdclass.com";
// String str3="xdclass.com";
// System.out.println(str1==str2);
// System.out.println(str2==str3);
// System.out.println(str1.equals(str2));
String str1=new String(" xDclass.com");
String str2="xdclass.com";
String str= "小弟课堂xdclass.net";
//获取字符串长度
System.out.println(str.length());
//通过下标获取字符
char ch=str.charAt(5);
System.out.println(ch);
//字符串比较
boolean result= str1.equals(str2);
System.out.println(result);
//字符串比较忽略大小写
boolean result1=str1.equalsIgnoreCase(str2);
System.out.println(result1);
//查找字符串出现的位置
int index=str.indexOf(".");
System.out.println(index);
//字符串截取
//从某个点以后截取
String result11=str.substring(index);
System.out.println(result11);
//截取范围
String result22=str.substring(1,3);//左闭右开1和2两个字符
System.out.println(result22);
//字符串拆分,注意特殊字符
// String [] arr= str.split("\\.");
String [] arr= str.split("x");
System.out.println("拆分"+arr.length);
//字符串替换
String tempDir=str.replace("x","a");
//字符串大小写转换
System.out.println(str.toUpperCase());
System.out.println(str.toLowerCase());
//字符串去除空格
System.out.println(str1.length());
System.out.println(str1.trim());
System.out.println(str1.length());
boolean bool=Boolean.getBoolean("false");//字符串类型转换为布尔类型
int integer=Integer.parseInt("20");//字符串类型转化为 整型
long longInt=Long.parseLong("1024");//字符串类型转化为长整型
float f=Float.parseFloat("2.1");//字符串类型转化为单精度浮点型
double d= Double.parseDouble("2.12523534");//字符串类型转化为双精度浮点型
}
}
四,java系统类之System类讲解
五,基本数据类型的包装数据类型讲解-面试题
package chapter14;
import java.util.ArrayList;
import java.util.List;
public class PacketTest {
private static float f4;
private static Float f5;
public static void main(String [] args){
// List<Integer> list=new ArrayList<>();
int i1=0;
Integer integer1 =new Integer(i1);
Integer integer2= new Integer(2);
int a=integer1.intValue();
Boolean booleanObj1=new Boolean(false);
boolean b=booleanObj1.booleanValue();
Float f= new Float(2.1);
float f1=f.floatValue();
Double d=new Double(2.3333);
Double D=d.doubleValue();
System.out.println(f4+"p"+f5);
}
}