java使用循环案例——CSDN博客
生活随笔
收集整理的這篇文章主要介紹了
java使用循环案例——CSDN博客
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** * @Title: test_while* @Description: 該方法的主要作用:while循環,輸出100個我愛編程* @param 設定文件 * @return 返回類型:void * @throws*/@Testpublic void test_while(){int i = 1;while (i<=100) {System.out.println("第"+i+"次,我愛編程!");i++;}}/*** * @Title: test_isHege* @Description: 該方法的主要作用:測試是否合格* @param 設定文件 * @return 返回類型:void * @throws*/@Testpublic void test_isHege(){String str = "";Scanner scanner = new Scanner(System.in);System.out.println("是否完成存息任務?(y|n):");str = scanner.next();while(!"y".equals(str)||"Y".equals(str)){System.out.println("上午閱讀教材!");System.out.println("下午上級編程!");System.out.println("是否完成存息任務?(y|n):");str = scanner.next();}System.out.println("完成學習任務了!");}/*** * @Title: test_dowhile* @Description: 該方法的主要作用:doWhile* @param 設定文件 * @return 返回類型:void * @throws*/@Testpublic void test_dowhile(){Scanner scanner = new Scanner(System.in);String str = "";do {System.out.println("上午編寫程序!");System.out.println("是否完成任務(y|n):");str = scanner.next();} while ("y".equals(str)||"Y".equals(str));System.out.println("完成任務");}
總結
以上是生活随笔為你收集整理的java使用循环案例——CSDN博客的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用java交换两个数——CSDN博客
- 下一篇: break 和continue的用法 j