例題:求圓的面積
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() 輸出后不換行