zoukankan      html  css  js  c++  java
  • java数据类型转换的常见方法

    public class Testfun {
    
    	public static void main(String[] args) {
    		// (一)跨Number父类的类型转换
    		// 1、str转int => Integer.parseInt(s1)
    		String s1 = "19";
    		int i2 = Integer.parseInt(s1);// 数字str转化为对标的int
    		System.out.println("++i2=" + (++i2));
    
    		// 2、int转str => Integer.toString(i3)
    		int i3 = 27;
    		String s4 = Integer.toString(i3);
    		System.out.println("s4=" + s4);
    
    		// 3、浮点转int => (int) d5
    		double d5 = 21.6;
    		int i6 = (int) d5;
    		System.out.println("i6=" + i6);
    
    		// 4、int转浮点 => (double) i7
    		int i7 = 60;
    		double d8 = (double) i7;
    		System.out.println("d8=" + d8);
    
    		// (二)同Number父类的类型转换
    		System.out.println();
    		Integer i9 = new Integer("17");
    		System.out.println(i9.intValue()); // 数字str转为int => i9.intValue()
    		System.out.println(i9.shortValue());// 数字str转为short => i9.shortValue()
    		System.out.println(i9.byteValue());// 数字str转为byte => i9.byteValue()
    
    		System.out.println();
    		// int转str(不同进制形式的str)
    		System.out.println(Integer.toString(456)); //获取10进制str
    		System.out.println(Integer.toBinaryString(456)); //获取2进制str
    		System.out.println(Integer.toHexString(456)); //获取16进制str
    		System.out.println(Integer.toOctalString(456)); //获取8进制str
    
    	}
    
    }
    

      

  • 相关阅读:
    javascript对象的几种创建方式
    webpack模块打包工具
    position的值, relative和absolute分别是相对于谁进行定位的
    实现快速排序
    实现冒泡排序:
    实现勾选框选中之后加个勾
    AJAX教程
    打印菱形
    快速创建简单的WCF跨平台服务
    .NET CORE 1.0, MVC6 & ANGULARJS2 -启动
  • 原文地址:https://www.cnblogs.com/andy9468/p/11081993.html
Copyright © 2011-2022 走看看