breakdemo.java

来自「Java样例程序集合:2D」· Java 代码 · 共 32 行

JAVA
32
字号
/**  * BreakDemo.java is an application that compiles and runs * under J2SE 5.0. It requires no other files. */public class BreakDemo {    public static void main(String[] args) {        int[] arrayOfInts = { 32, 87, 3, 589, 12, 1076,                              2000, 8, 622, 127 };        int searchfor = 12;        int i = 0;        boolean foundIt = false;	//We're not using for-each because we want	//to keep the value of i.        for ( ; i < arrayOfInts.length; i++) {            if (arrayOfInts[i] == searchfor) {                foundIt = true;                break;	    }        }        if (foundIt) {	    System.out.println("Found " + searchfor + " at index " + i);        } else {	    System.out.println(searchfor + "not in the array");        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?