Java programming 자바 프로그래밍 실습 : 원기둥 부피 구하기
2021-1 성균관대학교 소프트웨어학과 타메르 교수님의 자바 프로그래밍 실습 수업을 들으면서 수행한 예제입니다.
문제
원기둥의 부피를 구하는 자바 어플리케이션을 개발하라.
프로그램은 원기둥의 반지름과 높이를 입력받고, 그 결과를 출력한다.
// input
Radius (cm): 8
Height (cm): 15
// output
Volume of the cylinder: 3014.4
import java.util.Scanner;
public class Task1 {
public static void main(String[] args) {
// declare variables to use
// r is to store radius, h is for height, result is for the result of calculation
int r, h;
double result;
// declare Scanner to get console input
Scanner input = new Scanner(System.in);
System.out.print("Radius (cm): ");
r = input.nextInt();
System.out.print("Height (cm): ");
h = input.nextInt();
// this is for closing input stream (I refer to the QA board on Canvas.)
input.close();
// calculate the volume of the cylinder with inputs
result = 3.24 * r * r * h;
// print result
System.out.println("Volume of the cylinder: " + result);
}
}
'프로그래밍 언어 > Java' 카테고리의 다른 글
Java programming 자바 프로그래밍 실습 : 시험 시스템 (0) | 2021.03.11 |
---|---|
Java programming 자바 프로그래밍 실습 : 급여 계산기 (0) | 2021.03.11 |
Week3) Java Programming Lab : Class and Instance (0) | 2021.03.09 |
Week2) Java Programming Lab: Java vs. C++ (0) | 2021.03.01 |
Week 1) Java Programming Lab: Course Introduction (0) | 2021.02.23 |