我有一個BFS算法來解決8-Puzzle,並且其中一個項目要求是輸出找到最淺解決方案所花費的時間。如何正確顯示nanotime到第二次轉換
我使用System.nanoTime()
來跟蹤應用程序的運行時間,因爲它能夠在一秒鐘內解決大部分給定的難題。
我遇到的問題是我是否將我的nanoTime
轉換爲秒,它以奇怪的格式顯示。
以下代碼用於:
final long startTime = System.nanoTime();
//algorithm code removed for simplicity this all functions correctly
final long duration = System.nanoTime() - startTime;
final double seconds = ((double)duration/1000000000);
System.out.println("Nano time total: " + duration);
System.out.println("solution Time : " + seconds + " Seconds");
這將產生輸出:
Nano time total: 916110
solution time : 9.1611E-4 Seconds
我已經使用浮標表示值也嘗試。
是誰能夠提供更好的方式來轉換/顯示,也許使用格式輸出語句?
感謝您花時間閱讀我的問題。
9.1611E-4是表示數量的有效途徑。這只是科學記數法。 – hexafraction
關於格式化雙打有很多問題。你可以去看看他們。 – Justin