当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·*.xml文件可用何工具打开    »显示摘要«
    摘要: 同上 ......
 ·让我们今生在一起    »显示摘要«
    摘要: 女:如果有来生,你还会娶我吗? 男:不,绝不! 女:你。遂拿一本书投了过去,顺问着,为什么? 男:如果来生一样的过。没有新意,还不如不过?有什么意思 女:暗想,也是,如果下辈子不能在一起,请让我们今生互想珍惜! ......


java 的简单问题 13 p261

scjp   的考题  
   
  class         p260                     {     //an   apliacation  
          int   x=0;  
                    one   :    
          while   (x<10)   {  
                  two   :  
                  System.out.println(++x);  
                  if   (x>3)    
                  break   two;          
                   
                  }  
    }  
   
   
  运行出错,如何改正!

NO.1   作者: mercury1231

不知道要考什么?  
  break   one;?

NO.2   作者: cooled

代码不是静态且没包括在方法中

NO.3   作者: wantvictory

考什么,问题是什么,你怎么修改运行的。。。。。

NO.4   作者: SureBeiJing

这代码能编译通过吗?

NO.5   作者: zhjjava

p260.java:9:   undefined   label:   two  
                  break   two;  
                  ^  
  1   error  
  你应该给label   "two"给个范围,用{}来隔开!如下:  
   
  class         p260                     {     //an   apliacation  
      public   static   void   main(String   arg[]){  
              int   x=0;  
                    one:    
              while   (x<10)   {  
                  two:   {  
                  System.out.println(++x);  
                  if   (x>3)    
                      break   two;          
                  }  
              }  
        }          
  }  
  对于break的用法,下面我给你一帖子!

NO.6   作者: zhjjava

F1   Help:   Java   Keyword   -   breakbreak   14.13   The   break   Statement   A   break   statement   transfers   control   out   of   an   enclosing   statement.   BreakStatement:  
   
      break   Identifieropt   ;  
   
    A   break   statement   with   no   label   attempts   to   transfer   control   to   the   innermost   enclosing   switch,   while,   do,   or   for   statement;   this   statement,   which   is   called   the   break   target,   then   immediately   completes   normally.   To   be   precise,   a   break   statement   with   no   label   always   completes   abruptly,   the   reason   being   a   break   with   no   label.   If   no   switch,   while,   do,   or   for   statement   encloses   the   break   statement,   a   compile-time   error   occurs.   A   break   statement   with   label   Identifier   attempts   to   transfer   control   to   the   enclosing   labeled   statement   that   has   the   same   Identifier   as   its   label;   this   statement,   which   is   called   the   break   target,   then   immediately   completes   normally.   In   this   case,   the   break   target   need   not   be   a   while,   do,   for,   or   switch   statement.   To   be   precise,   a   break   statement   with   label   Identifier   always   completes   abruptly,   the   reason   being   a   break   with   label   Identifier.   If   no   labeled   statement   with   Identifier   as   its   label   encloses   the   break   statement,   a   compile-time   error   occurs.   It   can   be   seen,   then,   that   a   break   statement   always   completes   abruptly.   The   preceding   descriptions   say   "attempts   to   transfer   control"   rather   than   just   "transfers   control"   because   if   there   are   any   try   statements   within   the   break   target   whose   try   blocks   contain   the   break   statement,   then   any   finally   clauses   of   those   try   statements   are   executed,   in   order,   innermost   to   outermost,   before   control   is   transferred   to   the   break   target.   Abrupt   completion   of   a   finally   clause   can   disrupt   the   transfer   of   control   initiated   by   a   break   statement.   In   the   following   example,   a   mathematical   graph   is   represented   by   an   array   of   arrays.   A   graph   consists   of   a   set   of   nodes   and   a   set   of   edges;   each   edge   is   an   arrow   that   points   from   some   node   to   some   other   node,   or   from   a   node   to   itself.   In   this   example   it   is   assumed   that   there   are   no   redundant   edges;   that   is,   for   any   two   nodes   P   and   Q,   where   Q   may   be   the   same   as   P,   there   is   at   most   one   edge   from   P   to   Q.   Nodes   are   represented   by   integers,   and   there   is   an   edge   from   node   i   to   node   edges[i][j]   for   every   i   and   j   for   which   the   array   reference   edges[i][j]   does   not   throw   an   IndexOutOfBoundsException.   The   task   of   the   method   loseEdges,   given   integers   i   and   j,   is   to   construct   a   new   graph   by   copying   a   given   graph   but   omitting   the   edge   from   node   i   to   node   j,   if   any,   and   the   edge   from   node   j   to   node   i,   if   any:    
  class   Graph   {  
      int   edges[][];  
      public   Graph(int[][]   edges)   {   this.edges   =   edges;   }  
   
      public   Graph   loseEdges(int   i,   int   j)   {  
          int   n   =   edges.length;  
          int[][]   newedges   =   new   int[n][];  
          for   (int   k   =   0;   k   <   n;   ++k)   {  
   
              edgelist:   {  
                  int   z;  
   
                  search:   {  
                      if   (k   ==   i)   {  
                          for   (z   =   0;   z   <   edges[k].length;   ++z)  
                              if   (edges[k][z]   ==   j)  
                                  break   search;  
                      }   else   if   (k   ==   j)   {  
                          for   (z   =   0;   z   <   edges[k].length;   ++z)  
                              if   (edges[k][z]   ==   i)  
                                  break   search;  
                      }  
                      //   No   edge   to   be   deleted;   share   this   list.  
                      newedges[k]   =   edges[k];  
                      break   edgelist;  
                  }//search  
                  //   Copy   the   list,   omitting   the   edge   at   position   z.  
                  int   m   =   edges[k].length   -   1;  
                  int   ne[]   =   new   int[m];  
                  System.arraycopy(edges[k],   0,   ne,   0,   z);  
                  System.arraycopy(edges[k],   z+1,   ne,   z,   m-z);  
                  newedges[k]   =   ne;  
              }//edgelist  
          }  
          return   new   Graph(newedges);  
      }  
  }  
    Note   the   use   of   two   statement   labels,   edgelist   and   search,   and   the   use   of   break   statements.   This   allows   the   code   that   copies   a   list,   omitting   one   edge,   to   be   shared   between   two   separate   tests,   the   test   for   an   edge   from   node   i   to   node   j,   and   the   test   for   an   edge   from   node   j   to   node   i.

NO.7   作者: yyfzy

不清楚是什么

NO.8   作者: zhjjava

scjp   的考题  
   
  class         p260                     {     //an   apliacation  
          int   x=0;  
                    one   :    
          while   (x<10)   {  
                  two   :  
                  System.out.println(++x);  
                  if   (x>3)    
                  break   two;          
       
                  }  
    }  
   
   
  运行出错,如何改正!  
   
  改正如下:最贴切程序题义的,它想if   (x>3)   就停止!   改为break   one;哈哈,行了!  
   
  class         p260                     {     //an   apliacation  
      public   static   void   main(String   arg[]){  
              int   x=0;  
                    one:    
              while   (x<10)   {  
                  two:    
                  System.out.println(++x);  
                  if   (x>3)    
                      break   one;          
              }  
        }          
  }  
   
 


 ·第一个程序就出错了    »显示摘要«
    摘要: <html> <body> <form method="post" action="<?php echo $path_info?>"> 名:< type="text" name="first"><> 姓:< type="te......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE