|  | 
|  | 
| back to board | JAVA PROBLEM - "Time Limit Exceeded" import java.io.*;import java.util.*;
 
 public class Main
 {
 public static void main(String[] args) throws IOException
 {
 new Main().run();
 }
 
 StreamTokenizer in;
 PrintWriter out;
 
 void run() throws IOException
 {
 in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
 out = new PrintWriter(new OutputStreamWriter(System.out));
 solve();
 out.flush();
 }
 
 void solve() throws IOException
 {
 LinkedList<Double> myArr = new LinkedList<Double>();
 while(in.nextToken() != StreamTokenizer.TT_EOF)
 {
 myArr.add(Math.sqrt((double)(in.nval)));
 
 }
 myArr.add(0.0);
 ListIterator iterator = myArr.listIterator(myArr.size() - 1);
 while (iterator.hasPrevious())
 {
 out.printf("%.4f\n", iterator.previous());
 }
 }
 
 }
 
 I read the FAQS and other post but still cannot figure out whats the problem its working fine on my test cases which are as follows:
 
 Description: First 4 are input numbers rest is output.
 
 Test Case # 1:
 
 2
 5
 3
 5
 2.2361
 1.7321
 2.2361
 1.4142
 
 Test Case # 2:
 
 1427
 0
 876652098643267843
 5276538
 2297.0716
 936297014.1164
 0.0000
 37.7757
 
 Test Case # 3:
 
 1 2 3 4
 2.0000
 1.7321
 1.4142
 1.0000
 
 Test Case # 4:
 
 2
 4
 64
 49
 7.0000
 8.0000
 2.0000
 1.4142
 
 Why am i getting the time limit exceed error ?
Re: JAVA PROBLEM - "Time Limit Exceeded" You can solve this problem on Java in two ways:
 1. Use NumberFormat:
 
 NumberFormat nf = NumberFormat.getInstance(Locale.US);
 nf.setMaximumFractionDigits(6);
 nf.setGroupingUsed(false);
 out.println(nf.format(x));
 
 You can get AC in 1.14 sec in such way
 
 2. Use BigDecimal:
 
 out.println(BigDecimal.valueOf(x).setScale(6, RoundingMode.HALF_UP));
 
 You can get AC in 1.375 sec in such way
 | 
 | 
|