double除以int结果是int吗_游戏开发java中int可以用汉字吗?

超仔玩游戏

2020-05-0512:36

游戏开发java中int可以用汉字吗?简单试一下不就知道了,今天用的Eclipse版本是2020-03 (4.15.0),编写代码如下:

public class CalikoTest {

public static void main(String[] args) {

float operand1 = 10;

float operand2 = 10;

int operation = '战';

if (operation == '战') {

// 简单示例、并非真正游戏内战斗算法公式

System.out.println(operand1 + " + " + operand2 + " =");

System.out.println(operand1 + operand2);

} else if (operation == '暴') {

System.out.println(operand1 + " - " + operand2 + " =");

System.out.println(operand1 - operand2);

} else if (operation == '奶') {

System.out.println(operand1 + " * " + operand2 + " =");

System.out.println(operand1 * operand2);

} else {

System.out.println(operand1 + " / " + operand2 + " =");

System.out.println(operand1 / operand2);

}

}

}

ecfcce1fc70f8cd9ebd415756fd236f4.png

程序成功运行,但一个汉字占用2个字节,int只支持一个汉字。其实在以上程序中,string被自动转换为int进行比较,在这里用short、long、char、float、double也可以。

最后,看来在java八大基本类型中,除了一个字节的byte和JVM相关的boolean外,至少是都可以使用一个常见汉字的。

虽然在游戏程序设计里这并不是一种规范的良好习惯,但给我们提供了一种独特的方式,你可以发现程序初学者和大神有些都是很具有个性的 :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值