条件语句

本文介绍了一个简单的Java程序,用于模拟游戏角色的基本属性和行为,包括生命值、护甲、移动速度等,并实现了一些基本的方法,如攻击减血和判断死亡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



public class Hero {
String name;
float ht;
float armor;
int moveSpeed;
public void legendary() {
System.out.println("超神");
}
public void htDecate(float a) {
ht=ht-a;


}
static boolean die(float ht,String name) {
if(ht==0) {
System.out.println("died:"+name);
   return false;
    }
else {
System.out.println("alive:"+name);
return true;}
}


public static void main(String[] args) {
Hero Gaylun = new Hero();
Gaylun.name = "盖伦";
Gaylun.ht = 616.28f;
Gaylun.armor = 27.536f;
Gaylun.moveSpeed = 350;
System.out.printf("盖伦生命值:%f\n",Gaylun.ht);

Hero Timor = new Hero();
Timor.name = "提莫";
Timor.ht = 580.23f;
Timor.armor = 26.666f;
Timor.moveSpeed = 366;
Timor.htDecate(Timor.ht);

System.out.printf("提莫生命值:%f\n",Timor.ht);

boolean gd = die(Timor.ht,"提莫");
if(!gd)
System.out.println("rellaydied:");




}
}//不需要像C语言中加个return从函数中返回到全局中,只需要public,更不需要指针

//运用方法(函数时)也需要sb.方法

if用法差不多一样,借上熟悉一下print与方法的运用

switch也是

switch(day){
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            case 7:
                System.out.println("星期天");
                break;
            default:
                System.out.println("这个是什么鬼?");
        }
         
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值