当前位置: 代码迷 >> 综合 >> 每天一点基础
  详细解决方案

每天一点基础

热度:63   发布时间:2024-02-10 09:13:28.0

 

1)Math.ceil()执行向上取整,输出4

public static void main(String[] args) {System.out.println(Math.ceil(3.2));
}
}

2)Math.floor()执行向下取整,输出3

public static void main(String[] args) {System.out.println(Math.floor(3.2));
}
}

3)Math.round()执行四舍五入,输出3和4

public static void main(String[] args) {System.out.println(Math.round(3.2));System.out.println(Math.round(3.5));
}
}

4)基本类型 转换为Integer对象
1、  Integer in1=new Integer(10);
2、Integer in2=Integer.valueOf(20);

    Integer对象转换成int
1、int a=in1.intValue();


字符串转换成Integer对象
Integer in3=Integer.parseInt("324");
Integer in4=new Integer("999");

//Integer对象转换成字符串
String  str1=in3.toString();

5)StringBuffer和StringBuilder在频繁字符串修改失效测试

StringBuffer:线程安全 但是效率低

StringBuilder:线程不安全 但是效率高(一般用它)

  相关解决方案