[ 작업 환경 ]

 

Windows10

jdk-15

 

 

 

 

 

 

1. 반지름 입력하여 원 정보 출력하기 소스 작성 예시

 

//********************************************************************
//  CircleStats.java       Java Foundations
//
//  Demonstrates the formatting of decimal values using the
//  DecimalFormat class.
//********************************************************************

import java.util.Scanner;
import java.text.DecimalFormat;

public class CircleStats
{
   //-----------------------------------------------------------------
   //  Calculates the area and circumference of a circle given its
   //  radius.
   //-----------------------------------------------------------------
   public static void main (String[] args)
   {
      int radius;
      double area, circumference;

      Scanner scan = new Scanner (System.in);

      System.out.print ("Enter the circle's radius: ");
      radius = scan.nextInt();

      System.out.println(Math.PI);
      area = Math.PI * Math.pow(radius, 2);
      circumference = 2 * Math.PI * radius;

      // Round the output to three decimal places
      DecimalFormat fmt = new DecimalFormat ("0.###");

      System.out.println ("The circle's area: " + Double.toString(area));
      System.out.println ("The circle's area: about " + fmt.format(area));
      System.out.println ("The circle's circumference: "
                          + Double.toString(circumference));
      System.out.println ("The circle's circumference: about "
                          + fmt.format(circumference));
   }
}

 

 

 

 

 

 

2. 반지름 입력하여 원 정보 출력하기 결과 예시

 

 

 

 

 

+ Recent posts