Title: Calculates the area of the circle, where the radius of the circle is arbitrarily specified.
The source code and all the analysis ideas are as follows:
import java.util.scanner; //introduction of Scanner class public class testarea {/** * @param args */public static void main (String[] args) {// todo auto-generated method stub/* General Thinking Analysis 1. First, let the user enter the radius of the circle, because the radius is the arbitrarily specified 2. Using the round formula, The calculation of the area is 3. The value of the calculated area, the value of the area is stored in the variable 4. Output the area value to the console * title: Calculates the area of the circle, where the radius of the circle is arbitrarily specified. * */double r;double area;//Circular Area double round;//rounded perimeter final double pi=3.14;/ /here plus a final prevents the value of pi from being maliciously modified, where the value can only be assigned a constant once, and after the assignment the constant cannot be changed Scanner sc=new scanner (system.in); // Create an object of type scanner System.out.println ("Enter Circle radius First:"); R=sc.nextint (); //1. Wait for the user to enter a radius, 2. Store the radius of the input into the variable r area=pi*r*r; Round=2*pi*r; System.out.println ("Round area area=" +area); System.out.println ("Round circumference round=" +round);}}
As to the learning of this procedure, the summary is as follows:
I. Summary of the Scanner class
Scanner, like Heloworld, are classes that derive from the underlying class library of the system.
On the use of scanner, it needs to be introduced by the Import keyword
Scanner commonly used class methods:
Nextdouble (); Nextfoalt ();
Nextbyte (); Nextshort (); Nextlong (); Nextline ();
Second, questions about the final keyword:
You can use the final keyword to define a constant problem
Before final is in a variable, the real meaning is that it can only be assigned once
Constant naming, often use uppercase English words, if there are two or more words in English, directly with the underline connection . Example: Final int max_file_size
This article is from the "Sun nuo" blog, please be sure to keep this source http://10479756.blog.51cto.com/10469756/1945960
Java Learning Path---Calculate the area and perimeter of a circle