码迷,mamicode.com
首页 > 编程语言 > 详细

Java 程序测试_循环语句中的break和continue

时间:2015-03-01 23:37:35      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

package test;

public class Loop_Statement {
    public static  void main(String [] args)
    {
        String[] newbag = new String[] {"Bag","Key","Book"};
        
        //The usage of break
        int j = 0;
        while (j<newbag.length)
        {
            if(newbag[j] == "Key")
            {
                System.out.println("I have find the key!");
                break;
                //continue;
            }
            else
            {
                System.out.println("This is : "+newbag[j]+" , not key !");
            }
            j++;
        }
        
        //The usage of continue
        j = 0;
        while (j<newbag.length)
        {
            if (newbag[j]!="Book")
            {
                j++;
                continue;
            }
            System.out.println("I have find: "+newbag[j]);
            j++;
        }
    }
}

 

Java 程序测试_循环语句中的break和continue

标签:

原文地址:http://www.cnblogs.com/ghmgm/p/4307695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!