名前:上原和樹
番号:065709D
所属:情報工学科1年次
Volume.java |
---|
public class Volume { //球の体積 double sphiaVolume(double r) { return ((4*Math.PI*r*r*r)/3); } //直方体の体積 double recparaVolume(double w, double h, double l) { return(l*h*w); } //円錐の体積 double coneVolume(double h, double r) { return((Math.PI*r*r*h)/3); } } |
Rep3_1.java |
---|
public class Rep3_1 { public static void main(String args[]) { double r, h, w, l; Volume v = new Volume(); r = 3; h = 5; l = 4; w = 7; System.out.println("**********************************"); System.out.println("半径"+r+"の球の体積"); System.out.println("SV="+v.sphiaVolume(r)); System.out.println("**********************************"); System.out.println("幅"+w+", 長さ"+l+", 高さ"+h+"の直方体の体 積"); System.out.println("RPV="+v.recparaVolume(w, h, l)); System.out.println("**********************************"); System.out.println("半径"+r+", 高さ"+h+"の円錐の体積"); System.out.println("CV="+v.coneVolume(h,r)); } } |
********************************** 半径3.0の球の体積 SV=113.09733552923255 ********************************** 幅7.0, 長さ4.0, 高さ5.0の直方体の体積 RPV=140.0 ********************************** 半径3.0, 高さ5.0の円錐の体積 CV=47.1238898038469 |
Surface.java |
---|
public class Surface { //円錐の表面積 double coneSurface(double r, double h) { double A1 = Math.PI*r*r; double R = Math.hypot(r,h); double A2 = R*r*Math.PI; return(A1+A2); } //球の表面積 double sphireSurface(double r) { return(Math.PI*r*r*4); } } |
Rep3_2.java |
---|
public class Rep3_2 { public static void main(String args[]){ double r, h; r = 5; h = 4; Surface SA = new Surface(); System.out.println("************************************"); System.out.println("半径"+r+"高さ"+h+"の円錐の表面積"); System.out.println("SA="+SA.coneSurface(r,h)); System.out.println("************************************"); System.out.println("半径"+r+"の球の表面積"); System.out.println("SA="+SA.sphireSurface(r)); System.out.println("************************************"); } } |
************************************ 半径5.0高さ4.0の円錐の表面積 SA=179.11985666145375 ************************************ 半径5.0の球の表面積 SA=314.1592653589793 ************************************ |
Factrial.java |
---|
import java.io.*; class Factrial { public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)\); System.out.print("input natural number: "); int num = (new Integer(in.readLine())).intValue(); System.out.print("再帰呼び出しによる階乗計算 => "); System.out.println(num + "! =" + factrec(num)); } /* 再帰による階乗の計算 */ static int factrec(int number) { if ( number == 0 ) return(1); return( number*factrec(number-1) ); } } |
input natural number: 6 再帰呼び出しによる階乗計算 => 6! =720 |