<span style="font-family:Comic Sans MS;">public class ComputeArea {
public static void main(String []args){
final double PI=3.14159;
double area;
area=PI*10*10;
System.out.println("The area for the circle of 10 is "+area);
}</span>
<span style="font-family:Comic Sans MS;">
}<img src="https://img-blog.csdn.net/20140412112401781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyNjkyNg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
<span style="font-family:Comic Sans MS;">
</span>
<span style="font-family:Comic Sans MS;">
</span>
<span style="font-family:Comic Sans MS;">从控制台读取输入</span>
<span style="font-family:Comic Sans MS;">如何通过调用nextDouble()方法来读取带小数点的数。</span>
<span style="font-family:Comic Sans MS;"></span><pre name="code" class="java">import java.util.Scanner;//Scanner is in the java.util package
public class ComputeAreaWithConsoleInput {
public static void main (String args []){
//Create a Scanner object
Scanner input = new Scanner(System.in);
//Prompt the user to enter a radius
System.out.print("Enter a number for radius:");
double radius=input.nextDouble();
//Compute area
double area=radius*radius*3.14159;
//Display result
System.out.println("The area for the circle of radius "+radius+" is "+area);
}
}