日期:2014-05-20 浏览次数:20643 次
public class RootFromProduct { public double folge(double[] array)throws NegativeNumberException{ double sum=0; for(int i=0; i<array.length; i++){ if(array[i]<0) throw new NegativeNumberException(); sum += array[i]; } double result = Math.sqrt(sum); return result; } public static void main(String ... args) throws NegativeNumberException{ try{ double[] array = new double[100]; for(int i=0; i<args.length; i++){ array[i] = args[i]; } } catch(Exception ex){ } } }
public class RootFromProduct { public static double folge(double[] array)/*throws NegativeNumberException*/{ double sum=0; for(int i=0; i<array.length; i++){ if(array[i]<0) return sum ; //throw new NegativeNumberException(); sum += array[i]; } double result = Math.sqrt(sum); System.out.println(result ) ; return result; } public static void main(String[] args) /*throws NegativeNumberException*/{ try{ double[] array = new double[100]; for(int i=0; i<args.length; i++){ array[i] = Double.parseDouble(args[i]); } folge(array) ; } catch(Exception ex){ } } }