⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arithop2.java

📁 Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想
💻 JAVA
字号:
package chapter4;

public class ArithOP2 
{
	/**
	 * byte,short,int与long型混合运算。
	 * 如表达式中有一操作数为long型,则转换为long型运算,结果为long型。
	 * 如赋值给byte,short,int型需作强制类型转换
	 */
	public static void main(String[] args) 
	{		
		//long型与int型运算,结果超出int型范围,但因采用long型运算,结果不溢出。
		long maxInt= 2147483647L + 1; //结果为:2147483648
		System.out.println("maxInt=" + maxInt);
		short s = 5;
		long longShort = maxInt* s;//long型与short型作乘运算
		System.out.println("longShort=" + longShort);
		//long型与byte作取模运算,因采用long型计算,结果为long型,赋给int型时需作强制类型转换。
		byte b =3;
		int longByte = (int)(maxInt % b);
		System.out.println("longByte=" + longByte);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -