试炼二:变量、常量和基本数据类型:列举Java里面的8种基本数据类型、写出基本数据类型自动转化的流程图、实现两个整数的加减乘除以及取余算法、为抵抗洪水,战士连续作战89小时,计算共多少天零多少小时?

目录

1、列举Java中的八大基本类型?

 2、每种基本数据类型都定义一个常量(八个)。

3、每种基本数据类型都定义个变量(八个)。

4、写出基本数据类型自动转换的流程图。

5、实现两个整数的加减乘除以及取余运算 

6、实现两个字符型数据的加减乘除运算。

7、计算下列表达式的结果

 8、为抵抗洪水,战士连续作战89小时,编程计算共多少天零多少小时。

9、小明要到美国旅游,可是那里的温度是以华氏度为单位记录的。它需要一个程序将华氏温度(80度)转换为摄氏度,并以华氏度和摄氏度为单位分别显示该温度。

10、根据你的理解,说明一下“==”和“=”的区别。

11、根据运算符的功能,我们把运算符分成哪几类?

12、写出程序的输出结果

13、写出程序的输出结果

 14、写出程序的输出结果


1、列举Java中的八大基本类型?

byte 、short、int、long、float、double、char、boolean

 2、每种基本数据类型都定义一个常量(八个)。

public static void main(String[] args) {
		
		final byte BYTE = 127;
		final short SHORT = 256;
		final int INT = 15614156;
		final long LONG = 15451215;
		
		final float FLOAT = 3.1f;
		final double DOUBLE = 3.1415926;
		
		final char CHAR = 'A';
		
		final boolean BOOLEAN = true;
		
	}

3、每种基本数据类型都定义个变量(八个)。

public static void main(String[] args) {
		
		byte one = 127;
		short two = 1234;
		int three = 145151;
		long four = 84851466;
		
		float f = 1.2f;
		double d = 3.1415926;
		
		char c = 'A';
		boolean boo = true;
	}

4、写出基本数据类型自动转换的流程图。

5、实现两个整数的加减乘除以及取余运算 

public static void main(String[] args) {
	
		int a = 15;
		int b = 4;
		int result;
		
		result = a + b;
		System.out.println("15 + 4 = "+result);
		
		result = a - b;
		System.out.println("15 - 4 = "+result);
		
		result = a * b;
		System.out.println("15 * 4 = "+result);
		
		result = a / b;
		System.out.println("15 / 4 = "+result);
		
		result = a % b;
		System.out.println("15 % 4 = "+result);
	}

6、实现两个字符型数据的加减乘除运算。

public static void main(String[] args) {
	
		char charOne = 'H';
		char charTwo = 'b';
		int result;
		
		result = charOne + charTwo;
		System.out.println("H + b = "+result);
		
		result = charOne - charTwo;
		System.out.println("H - b = "+result);
		
		result = charOne * charTwo;
		System.out.println("H * b = "+result);
		
		result = charOne / charTwo;
		System.out.println("H / b = "+result);
		
		result = charOne % charTwo;
		System.out.println("H % b = "+result);
	}

7、计算下列表达式的结果

10/3 ; 10/5 ; 10%2 ; 10.5%3;

 8、为抵抗洪水,战士连续作战89小时,编程计算共多少天零多少小时。

public class Day {
	public static void main(String[] args) {
		
		int num = 89;
		int day;
		int hour;
		
		day = num / 24;
		hour = num % 24;
		
		System.out.println("共"+day+"天"+hour+"小时");
		
	}

}

9、小明要到美国旅游,可是那里的温度是以华氏度为单位记录的。它需要一个程序将华氏温度(80度)转换为摄氏度,并以华氏度和摄氏度为单位分别显示该温度。

提示:摄氏度与芈氏度的转换公式为:摄氏度 = 5/9.0*(华氏度-32)

public static void main(String[] args){
		double dc;
		int fd=80;
		dc=5/9.0*(fd-32);
		System.out.println("80华氏度="+dc+"摄氏度");
	}

10、根据你的理解,说明一下“==”和“=”的区别。

 “==”是比较两个基本数据类型的值是否相等;

    “=” 表示赋值

11、根据运算符的功能,我们把运算符分成哪几类?

赋值运算符、 算术运算符、关系运算符、逻辑运算符、位运算符、条件运算符

12、写出程序的输出结果

13、写出程序的输出结果

 14、写出程序的输出结果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值