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();}
}
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();}
}
相关文章推荐
- 面向对象编程中的设计模式
- 团队绩效评比
- 实验三 交换机的基本配置与管理
- 下载字体库的地址
- STL中vector查找算法find()和find_if()深入比较
- Ubuntu下使用Eclipse和PyDev搭建完美Python开发环境
- 2016/4/28所学大致总结
- linux3.4.2移植
- 系统移植-文件系统移植
- 驱动开发-模块
- Docker Hub 的伟大在那里?
- java web Filter过滤器解决乱码
- Android进阶UI之百分比布局库(percent-support-lib) 解析与扩展
- vtk实战(二十一)——写入STL格式
- Java中的线程池
- c++ 11(五)
- leetcode46/47-Permutations I/II(全排列问题)
- 关于Android Force Close 出现的原因 以及解决方法
- 九、堆与优先队列---(3)输出堆中元素并获取和删除堆顶元素
- 系统移植-uboot移植