java - to check how many roots are real -
import java.util.scanner; public class fileoutputstreamexample { public static int count; public void equation(int a, int b,int c) { int e=(b*b)-(4*a*c); double f=math.pow(e,1/2); if(f>=0) count=count++; } public static void main (string []args) { fileoutputstreamexample fos= new fileoutputstreamexample(); scanner sc= new scanner(system.in); int n= sc.nextint(); for(int i=1;i<=n;i++) { int a= sc.nextint(); int b= sc.nextint(); int c= sc.nextint(); fos.equation(a, b, c); } system.out.println("ans "+count); } } here writing code check if given n inputs of quadratic equation having having coefficients a,b,c how many of given n inputs have real roots. code compiles possible results in ans=0 time. count not working in case.
count=count++;
this line nothing. increments count, returns value expression, stored in count. since ++ @ end, value being stored original value of count, undoing increment. :)
when using increment (or decrement) operators, don't have use assignment operator modify value. increment implies modification variable.
fix changing to: count++;
in addition that, 1/2 equal zero, since operands integers, , such, division applied integer division (which truncates decimal parts) rather division you're expecting.
change 1.0/2 or .5
Comments
Post a Comment