Think in java 答案

    技术2022-05-11  130

    阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx

    /****************** Exercise 5 ****************** * Modify Exercise 4 so that the program exits by * using the break keyword at value 47. Try using * return instead. ***********************************************/public class E05_Break47 {  public static void main(String[] args) {    for(int i = 1; i <= 100; i++) {      System.out.println(i);      // if(i == 47) break;      if(i == 47) return;    }  }} 

     //+M java E05_Break47

    **The above example includes a commented line of code to use break, as well. The break will exit the for loop, which puts it at the end of main( ), whereas return exits directly from the current method, which happens to be main( ).


    最新回复(0)