Java Learning Path---Calculate the area and perimeter of a circle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.