今天复习java的流程结构,还是那句话,基础还是很重要.
1.switch
public class TestSwitch {public static void main(String[] args) {int a = 1;// String b = "今天是";switch (a) {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("there is nothing");} } }
2.do-wihile
do {System.out.println("至少让我执行一次");} while (i > 10);
3.for
阶乘
public class TestFor {public static void main(String[] args) {// 阶乘求值int jiecheng = 1;int num = 0;for (int i = 1; i < 10; i++) {jiecheng *= i;num += jiecheng;System.out.println(jiecheng);}System.out.println(num);} }
蜜汁706
int bf, mf, lf;for (bf = 0; bf < 20; bf++) {for (mf = 0; mf < 100; mf++) {for (lf = 0; lf < 100; lf++) {if ((bf + mf + lf == 100) && (bf * 5 + mf + lf * 0.5 == 100)) {System.out.println(bf + " " + mf + " " + lf);}}}}
补充一下,可以用for(;;)来进行无限循环,因为这个根本不用判断,不像while True每次都要判断,也算一点点性能优化吧
break&continue&return
public class TestBreakContinueReturn {public static void main(String[] args) {for (int i = 1; i < 4; i++) {System.out.println("这是第" + i + "次外循环");for (int j = 1; j < 4; j++) {System.out.println("t" + "这是第" + j + "次内循环");break;}}for (int a = 1; a < 10; a++) {if (a == 6) {continue;}System.out.println(a);}for (int a = 1; a < 10; a++) {if (a == 8) {return;}System.out.println(a);}System.out.println("helloworld");} }
break是跳出当前循环;continue是跳过当前操作继续循环;return是调处整个main方法
今天学到了activity的查看方法,很开心,很有成就感,不过今晚得把appium给入门了,干!!!
转载于:.html
本文发布于:2024-01-31 17:56:31,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170669499230323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |