首先查看代码:
public class BreakTesting {
public static void main(String[] args){
int[] arrayOfInts={32,54,13,69,75,30,11,5,89};
System.out.println("Type in the Num:");
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
boolean bl=false;
int j=0;
for(j=0;j<arrayOfInts.length;j++){
if(i==arrayOfInts[j]){
bl=true;
break;
}
}
if(bl){
System.out.println("Found "+i+" at index "+(j+1));
}else{
System.out.println(i+ " not found");
}
}
}
outprint:
Type in the Num:
5
Found 5 at index 8
含break的代码块:
for(j=0;j<arrayOfInts.length;j++){
if(i==arrayOfInts[j]){
bl=true;
break;
}
}
break的功能是从该语句所在的switch or 循环中跳出来,执行后续的语句。
注意:
arrayOfInts.length是从1开始的,而Index是从0开始的,arrayOfInts[j],如果int j=arrayOfInts.length就会抛出:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9
at Ttt.BreakTesting.main(BreakTesting.java:14)
分享到:
相关推荐
Idiot‘s_Guides_to_Beginning_Programming.pdf
傻瓜指南系列-如何作小生意]The.Complete.Idiot's.Guide.-.Small.Business.pdf
An Idiot's Guide to C++ Templates
The Complete Idiot's Guide to Improving Your IQ.pdf
Idiot
The Complete Idiot’s Guide to iPad and iPhone App Development .pdf
Explorer扩展编程的指导资料,包括一个chm教程以及其对应的源代码。 Part I - A step-by-step tutorial on writing shell extensions Part II - A tutorial on writing a shell extension that operates on ...
详细说明Windows Shell的编程指南,可以处理Windows Explorer资源管理器很多的交互,比如文件复制和剪切,鼠标右键菜单的添加,任意文件的图标的修改和叠加,系统文件拷贝进度条的控制等等,文件属性自定义扩展页和...
idiot
自动 线性采样 PID control automatique li1 Introduction 9 1.1 D e nition . . . . . . ....1.2 Exemples d'asservissements ....1.2.1 Historique ....1.3 Mise en uvre des asservissements num eriques ....
An Idiot’s guide to Support vector machines (SVMs)
HTML Reference for dummies, idiot, beginner
加密已有文件,可以临时加密和永久解密;加密特定文件夹
This guide helps environmentally conscious people make real-world ...·More than 80 regional and local green building programs are in place in the U.S. and more are being promoted in the private sector
Title: Soft Skills: The software developer’s life manual Author: John Sonmez Length: 504 pages Edition: 1 Language: English Publisher: Manning Publications Publication Date: 2014-12-29 ISBN-10: ...
most simple adding for those idiot
CSS 2 Reference for begginer, idiot, dummies
American Idiot is the seventh studio album by American rock band Green Day