• Java数据类型转换


    /**
     * @Title:TypeTransform.java
     * @Package:com.you.dao
     * @Description:Java类型转换
     * @Author: 游海东
     * @date: 2014年3月8日 下午9:05:55
     * @Version V1.2.3
     */
    package com.you.dao;
    
    /**
     * @类名:TypeTransform
     * @描述:类型转换(byte,short,char)- int - long - float - double 
     * @Author:游海东
     * @date: 2014年3月8日 下午9:05:55
     */
    public class TypeTransform 
    {
    	/**
    	 * 
    	 * @Title : main
    	 * @Type : TypeTransform
    	 * @date : 2014年3月8日 下午9:26:10
    	 * @Description : 
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		/**
    		 * 字节a
    		 */
    		byte a = 12;
    		/**
    		 * 短整型b
    		 */
    		short b = 13;
    		/**
    		 * 字符c
    		 */
    		char c = 'A';
    		/**
    		 * 整型d
    		 */
    		int d = 45;
    		/**
    		 * 长整型e
    		 */
    		long e = 56l;
    		/**
    		 * 单精度f
    		 */
    		float f = 12.31f;
    		/**
    		 * 双精度g
    		 */
    		double g = 69.36;
    		/**
    		 * 整型h
    		 */
    		int h = 9;
    		
    		/************************byte,short,char转换为int***************************************/
    		/**
    		 * 打印条件表达式 a
    		 */
    		System.out.println((h > 10)?124:a);
    		/**
    		 * 打印条件表达式 b
    		 */
    		System.out.println((h > 10)?124:b);
    		/**
    		 * 打印条件表达式 c
    		 */
    		System.out.println((h > 10)?124:c);
    		
    		/************************byte,short,char,int转换为long***************************************/
    		/**
    		 * 打印条件表达式 a
    		 */
    		System.out.println((h > 10)?124l:a);
    		/**
    		 * 打印条件表达式 b
    		 */
    		System.out.println((h > 10)?124l:b);
    		/**
    		 * 打印条件表达式 c
    		 */
    		System.out.println((h > 10)?124l:c);
    		/**
    		 * 打印条件表达式 d
    		 */
    		System.out.println((h > 10)?124l:d);
    		
    		/************************byte,short,char,int,long转换为float***************************************/
    		/**
    		 * 打印条件表达式 a
    		 */
    		System.out.println((h > 10)?124.2f:a);
    		/**
    		 * 打印条件表达式 b
    		 */
    		System.out.println((h > 10)?124.2f:b);
    		/**
    		 * 打印条件表达式 c
    		 */
    		System.out.println((h > 10)?124.2f:c);
    		/**
    		 * 打印条件表达式 d
    		 */
    		System.out.println((h > 10)?124.2f:d);
    		/**
    		 * 打印条件表达式 e
    		 */
    		System.out.println((h > 10)?124.2f:e);
    		
    		/************************byte,short,char,int,long,float转换为double********************/
    		/**
    		 * 打印条件表达式 a
    		 */
    		System.out.println((h > 10)?12.3:a);
    		/**
    		 * 打印条件表达式 b
    		 */
    		System.out.println((h > 10)?12.3:b);
    		/**
    		 * 打印条件表达式 c
    		 */
    		System.out.println((h > 10)?12.3:c);
    		/**
    		 * 打印条件表达式 d
    		 */
    		System.out.println((h > 10)?12.3:d);
    		/**
    		 * 打印条件表达式 e
    		 */
    		System.out.println((h > 10)?12.3:e);
    		/**
    		 * 打印条件表达式 f
    		 */
    		System.out.println((h > 10)?12.3:f);
    		/**
    		 * 打印条件表达式 g
    		 */
    		System.out.println((h > 10)?12.3:g);
    	}
    }

    运行结果:

    12
    13
    A
    12
    13
    65
    45
    12.0
    13.0
    65.0
    45.0
    56.0
    12.0
    13.0
    65.0
    45.0
    56.0
    12.3100004196167
    69.36
    



  • 相关阅读:
    IDA 动态调试 ELF 文件
    双机调试环境搭建[win7+Windbg+VirtualKD]
    从域环境搭建到 MS14-068 提升为域权限
    栈溢出原理与 shellcode 开发
    Flask_0x05 大型程序结构
    rest-framework 框架的基本组件
    restful 规范
    Django的CBV和FBV
    Django-model 进阶
    Django-Ajax
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315316.html
Copyright © 2020-2023  润新知