Java 实例 - break 关键字用法

Java 教程 · 2019-02-10 16:41:57

Java break 语句可以直接强行退出当前的循环,忽略循环体中任何其他语句和循环条件测试。

以下实例使用了 break 关键字来跳出当前循环:

Main.java 文件

public class Main { public static void main(String[] args) { int[] intary = { 99,12,22,34,45,67,5678,8990 }; int no = 5678; int i = 0; boolean found = false; for ( ; i < intary.length; i++) { if (intary[i] == no) { found = true; break; } } if (found) { System.out.println(no + " 元素的索引位置在: " + i); } else { System.out.println(no + " 元素不在数组中"); } } }

以上代码运行输出结果为:

5678 元素的索引位置在: 6

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich、Roberto Tamassia、Michael H. Goldwasser / John Wiley & Sons / 2013-7-5 / GBP 121.23

Based on the authors' market leading data structures books in Java and C++, this book offers a comprehensive, definitive introduction to data structures in Python by authoritative authors. Data Struct......一起来看看 《Data Structures and Algorithms in Python》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具