静态检测

静态检测能够发现的错误

  • 语法错误
  • 错误的方法名(如Math.sine(2))
  • 错误的方法参数个数(如Math.sin(2,3))
  • 错误的参数类型(如Math.sin(“30”))
  • 错误的返回类型

动态检测能够发现的错误

  • 不合法的参数值,如2/0.
  • 索引超出范围
  • 调用了为null的方法
  • 返回值的类型未知

hailstone sequence

 import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
 public class Hailstone {
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    /**computer a hailstone sequence
     * @param n Starting number for sequence.Assumes n > 0.
     * @return Hailstone squence starting with n and end with 1.
     */
   Scanner ns = new Scanner(System.in);
   int number = ns.nextInt();
   Listlist = new ArrayList();
   while (number != 1)
   {
       list.add(number);
       if (number % 2 == 0 )
       {
           number = number /2;
       }
       else
       {
           number = 3 * number + 1;
       }
       
   }
   list.add(number);
   System.out.println(list);
}
 }

你可能感兴趣的:(静态检测)