zoukankan      html  css  js  c++  java
  • java使用循环案例——CSDN博客

    /**
    	 * 
    	* @Title: test_while
    	* @Description: 该方法的主要作用:while循环,输出100个我爱编程
    	* @param   设定文件  
    	* @return  返回类型:void   
    	* @throws
    	 */
    	@Test
    	public void test_while(){
    		int i = 1;
    		while (i<=100) {
    			System.out.println("第"+i+"次,我爱编程!");
    			i++;
    		}
    	}
    
    	/**
    	 * 
    	* @Title: test_isHege
    	* @Description: 该方法的主要作用:测试是否合格
    	* @param   设定文件  
    	* @return  返回类型:void   
    	* @throws
    	 */
    	@Test
    	public 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
    	 */
    	@Test
    	public 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("完成任务");
    	}

  • 相关阅读:
    Leetcode 121. Best Time to Buy and Sell Stock
    Leetcode 120. Triangle
    Leetcode 26. Remove Duplicates from Sorted Array
    Leetcode 767. Reorganize String
    Leetcode 6. ZigZag Conversion
    KMP HDU 1686 Oulipo
    多重背包 HDU 2844 Coins
    Line belt 三分嵌套
    三分板子 zoj 3203
    二分板子 poj 3122 pie
  • 原文地址:https://www.cnblogs.com/a1111/p/12816200.html
Copyright © 2011-2022 走看看