收藏 分销(赏)

java 基本语句.doc

上传人:xrp****65 文档编号:7038275 上传时间:2024-12-25 格式:DOC 页数:5 大小:16.18KB 下载积分:10 金币
下载 相关 举报
java 基本语句.doc_第1页
第1页 / 共5页
java 基本语句.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
Java基本语句 IF语句 第一种: class if { public static void main (String[] args) { int x=8; if(x<9) { System.out.println("haha"); } } } 第二种: class textif { public static void main (String[] args) { int x=5; if(x<4) { System.out.println("haha"); } else { System.out.println("gege"); } System.out.println("bbbbbbbb"); } } 第三种: class ccc { public static void main (String[]args) { int x=6; if(x<1) { System.out.println("haha"); } else if(x<8) { System.out.println("hehe"); } else { System.out.println("heihei"); } } } Switch语句: class ddd { public static void main (String[]args) { int x=8; switch(x) { case 4: System.out.println("haha"); break; case 8: System.out.println("hehe"); break; case 6: System.out.println("hihi"); break; default: System.out.println("gaga"); break; } } } 循环语句 1:while语句 class fff { public static void main (String[]args) { int x=2; while(x<4) { System.out.println("x="+x); x++;//ctrl+c 停止当前DOS循环。 } } } 2:do while语句 class ggg { public static void main(String[]args) { int x=3; do { System.out.println("x="+x); x++; } while(x<8); } } 3:for语句 1:关键词 break class hhh { public static void main(String[]args) { for(int x=0;x<5;x++) { System.out.println("x="+x); } System.out.println("---------------"); for(int x=7;x<14;x++) { System.out.println("x="+x); break;//break作用:第一次循环到此结束,不往下继续循环。 } } } 2:关键词 continue class jjj { public static void main(String[]args) { for(int x=1;x<=10;x++) { if(x%2==1) continue; System.out.println("x="+x); } } } For嵌套循环 class ppp { public static void main(String[]args) { int z=1; for(int x=0;x<5;x++) { for(int y=0;y<z;y++) { System.out.print("*"); } z++; System.out.println(); } } } 打印结果 * ** *** **** *****
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服