条件语句

论坛 期权论坛 脚本     
匿名技术用户   2021-1-6 18:09   56   0


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( "这个是什么鬼?" );
}
}
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP