読者です 読者をやめる 読者になる 読者になる

演算 Java

概要

変数を宣言し、値を代入後四則演算をする。

public class Variables {
	public static void main(String[] args) {

		byte data1 = 127;
		short data2 = 32767;
		int data3 = 2147483647;
		float data4 = 1.2345678F;
		double data5 = 123456789.012345;
		char data6 = 'z';
		long data7 = 9223372036854775807L;
		String data8 = "文字列定数";
		boolean data9 = true;

		System.out.println("byteVariable = " + data1);
		System.out.println("shortVariable = " + data2);
		System.out.println("intVariable = " + data3);
		System.out.println("floatVariable = " + data4);
		System.out.println("doubleVariable = " + data5);
		System.out.println("charVariable = " + data6);
		System.out.println("longVariable = " + data7);
		System.out.println("stringVariable = " + data8);
		System.out.println("booleanVariable = " + data9);
	}
}

実行結果

和  int_add = 19134
差  int_sub = 5556
積  int_mult = 83810205
商  int_div = 1
剰余  int_mod = 5556
商  int_div = 1.8183826