您的位置:首页 > 其它

if语句与switch的使用

2016-04-28 23:28 211 查看
JAVA的入门基础。

Hello world

首先在环境中新建JavaProject,右击src包,找到Package,建立包名,再在报名中建立class.在类的下面输入public
static void main(String[] args)主函数,在主函数中输入System.out.println("hello world");这样就可以输出Hello world

定义季节的if语句

Public static void main(String[] args){

Int a=?;

If(a<6&a>2){System.out.println(“春天”);}

If(a<7&a>5){System.out.println(“夏天”);}

If(a<12&a>8){System.out.println(“秋天”);}

If(a<3||a>11){System.out.println(“冬天”);}

}

用switch定义季节

Public static void main(String[] args){

Int a=?;

Switch(a){

case3:

case4:

case5:

Sysem.out.println(“春天”);

Break;

case6:

case7:

case8:

System.out.println(“夏天”);

Break;

Case9:

Case10:

Case11:

System.out.println(“秋天”);

Break;

Case12:

Case1:

Case2:

System.out.println(“冬天”);

Break;}

双层for循环语句

pubich strict void main(string[] args)

{ for(int x=0;x<4;x++){

for(int y=0;y<4;y++){

System.out.print(“*”);

}

System.out.println();}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: