|
|
вернуться в форумWhere is the problem ?, write in java this is a part of my code, this find the value of array parameters (not contain the size). but the judge respond wrong answer. Why? public StringBuffer procesar(int [] array){ StringBuffer res = new StringBuffer(); String cad = ""; for(int i=0;i<array.length;i++){ int val = array[i]; if(val == 1){ cad = "1"; }else { double dVal = cuad(1,1,(-1)*((2*val)-2)); if(isValidate(dVal)) cad = "1"; else cad = "0"; } res.append(cad); } return res; } public boolean isValidate(double val){ boolean res = false; double cmp = Math.round(val); if(val == cmp) res = true; return res; } public double cuad(int a, int b, int c){ double res = 0; double x1 = ((-1)*b + Math.sqrt(b*b + ((-4)*a*c)))/(2*a); double x2 = ((-1)*b - Math.sqrt(b*b + ((-4)*a*c)))/(2*a); if(x1 > 0){ res = x1; }else { res = x2; } return res; } |
|
|