Java中四舍五入保留七位小數


例題:求圓的面積

 

String.format("%.7f", s)的用法

 

import java.util.Scanner;
public class Main {
   public static void main(String[] args){

       Scanner sc= new Scanner(System.in);
       int r=sc.nextInt();


       double PI=3.14159265358979323;   //圓周率
       double s=PI*r*r;   //面積
       System.out.println(String.format("%.7f", s));   //結果保留七位小數

      }
}

 

println() 輸出后換行
print() 輸出后不換行

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM