|
|
back to boardhelp in java import java.util.Scanner; public class Reverseroot { public static void main(String args[]) { solve(); } public static void solve() { Scanner s=new Scanner(System.in);
while(s.hasNext()) { double t=s.nextDouble(); solve(); double n=(double) Math.sqrt(t); System.out.printf("%.4f\n",n); } } } what is wrong in my solution .. could somebody give me the solution of this problum in C Did you try your solution for the sample? Re: Did you try your solution for the sample? i tried it on my linux machine and it is giving me right solution..may b problem due to exceed limti i tried it using BIGDECIMAL also here is my code but it is giving a crash .... import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.Scanner; import java.io.StreamTokenizer; public class Reverseroot { public static void main(String args[]) { solve(); } public static void solve() { Scanner s=new Scanner(System.in); while(s.hasNext()) { BigInteger b=new BigInteger(s.nextLine()); solve(); double x=Math.sqrt(b.doubleValue()); System.out.println(BigDecimal.valueOf(x).setScale(4, RoundingMode.HALF_UP)); } } } frnds i need help Re: help in java Posted by Davor 10 Mar 2009 01:38 Put this while loop in try/catch block. I had the same problem, judge reported crash on my program. That fixed it. Seams to me that .hasNext() is the problem. And eliminate recursion, for gods sake!! You have one stack frame for every number, and u have 256k of numbers. Its incredibly inefficient. |
|
|