Chinaunix

标题: java程序设计入门教程习题--第四章(三) [打印本页]

作者: boean    时间: 2010-01-19 13:57
标题: java程序设计入门教程习题--第四章(三)
初学者做习题

6.已知圆的面积Area = ∏×r×r,求半径r。

//已知圆的面积,求半径r
public class Xiti4q6 {
final float PI=3.14159f; //定义一个用于表示圆周率的常量PI
public  void getR(){
  double r;
  double Area=60;
  double M=Area/PI;
  r=Math.sqrt(M);
  System.out.println("圆的半径是" +r);
}

  
public static void main(String[] args)
{
Xiti4q6 banjin= new Xiti4q6();
banjin.getR();

}
}

----------------------------------------------------
####################################################
7.使用Math类中的random()方法,模拟一个铜板在连续一百次的投掷中,出现正反面的次数。

//使用Math类中的random()方法,模拟一个铜板在连续一百次的投掷重
//出现反面的次数
public class Xiti4q7 {
int a;
int b;

public void up_down() {
  for (int i = 1; i
}
public static void main(String[] args) {
  Xiti4q7 face_back = new Xiti4q7();
  face_back.up_down();

}
}

-------------------------------------------
#############################################
8.模拟一个骰子在连续一万次的投掷中,一至六点出现的次数。
  此题如果有更好的方法请大侠贴出来
//模拟一个骰子在连续一万次的投掷中一至六点出现的次数
public class Xiti4q8 {
public void shaizi() {
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  int e = 0;
  int f = 0;
  for (int i = 1; i


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/19637/showart_2153048.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2