讓我曾經蛋疼的錯誤

public class Stringtoint {
 
  public static void main(String[] args) {
             int w = new Integer(args[0]).intValue();
             int h = Integer.parseInt(args[1]);
             for(int i=0;i<w;i++)
             {
                       StringBuffer sb = new StringBuffer();
                        for(int j=0;j<h;j++);                          //循環出錯,原因是多了一個'  ;  '
                       {
                              sb.append("*");

                        }
                      System.out.println(sb.toString());

  }
 } 
}
*********************************

import java.util.*;
public class TestVector {
 
 public static void main(String[] args)

 {
                    Vector v = new Vector();
                    int b = 0;
                    System.out.println("Please enter number:");
                    while(true);   //這裏又出現 ;了啊啊啊,所以纔有break必須出現在循環switch中的提示
                    {
   
                                 try
                                 {
                                 b = System.in.read();     //int b = System.in.read();b在{}中,所以,他的有效範圍就在{}中 
                                 }
                                catch(Exception e)
                                 {
                                e.printStackTrace();
                                 }
   
                                if(b == '\r'||b == '\n')
                                 {
                                    break ;           //錯誤: 在 switch 或 loop 外部中斷
                                 }
                                else
                                {
                                int num = b - '0';
                               v.addElement(new Integer(num));
                                }
    
                }
  int sum = 0;
  Enumeration e = v.elements();
  while(e.hasMoreElements())
  {
   Integer intObj = (Integer)e.nextElement();
   sum += intObj.intValue();
  }
  System.out.println(sum);
 } 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章