if语句与switch的使用

来源:互联网 发布:怎么成为算法工程师 编辑:程序博客网 时间:2024/05/01 11:36

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();}

}

 

 

 

 

1 0
原创粉丝点击