不知道 jfreechart 可以不,我只知道他可以画不少图哦,不过为什么要用java画呢,不知道楼主想要实现什么业务,不过这样有点扬短避长哦
解决方案 »
- eclipse运行时老是404
- subclass's has not only one entity manager property帮我看看这个异常怎么解决?
- java swing 的 JComboBox 能像html中的select一样将显示值和实际值对应吗?
- java pet store2.0怎样配置
- struts如何控制一个frame跳转
- 请教javamail问题(发送邮件)
- 登陆后启动tomcat为什么一关闭登陆,tomcat自动会关掉
- 深入浅出学JEE事务
- 请教大虾,jbuilderX+WebLogic8.1 错误!
- jdbc driver 何处寻???
- Struts中 修改记录 在页面表单上value怎么得到原来的数据
- hibernate+JTDS+tomcat5连不上数据库
在web上画可以用vml来搞,如果就在java的from里用java的绘图方法就直接把直线坐标算好用line来画就完了
2,求阶乘可以用递归,
public static BigDecimal jiecheng(BigDecimal n) {
if (n.equals(new BigDecimal(1)))
{
return new BigDecimal(1);
} else {
return n.multiply(jiecheng(n.subtract(new BigDecimal(1))));
}
}
偶又来推荐一个果子大大(火龙果)的文章,相当好!
http://blog.csdn.net/bao110908/archive/2007/11/27/1904452.aspx
阶乘如果很大,就用BigDecimal来处理!
以下代码转自:http://blog.sina.com.cn/s/blog_49016589010092mo.htmlimport java.awt.*;
import javax.swing.*;public class WuJiaoXing extends JPanel { private static final long serialVersionUID = 1L; private JFrame frame = null; private int r = 150; // 外顶点外接圆半径 private int[] x = new int[5]; // 5个X外顶点坐标 private int[] y = new int[5]; // 5个Y外顶点坐标 private int[] x_ = new int[5]; // 5个X内顶点坐标 private int[] y_ = new int[5]; // 5个Y内顶点坐标 public WuJiaoXing() {
this.math();
frame = new JFrame("五角星");
frame.getContentPane().add(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLocation(200, 200); frame.setVisible(true);
} private void math() {
int c = 360 / 5; // 角度
for (int i = 0; i < 5; i++) {
x[i] = (int) (Math.cos(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
y[i] = (int) (Math.sin(i * c * Math.PI / 30 - Math.PI / 2) * (r) + r);
}
int r_ = (int) (r * Math.sin(18 * Math.PI / 180) / Math
.sin(126 * Math.PI / 180)); // 内顶点外接圆半径
for (int i = 0; i < 5; i++) {
x_[i] = (int) (Math.cos((i * c + 18) * Math.PI / 30 - Math.PI / 2)
* (r_) + r);
y_[i] = (int) (Math.sin((i * c + 18) * Math.PI / 30 - Math.PI / 2)
* (r_) + r);
}
} public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.YELLOW);
// g.setBackground(Color.RED);
// 填充
int[] x1 = { x[0], x[2], x_[2] };
int[] y1 = { y[0], y[2], y_[2] };
int[] x2 = { x[1], x[3], x_[3] };
int[] y2 = { y[1], y[3], y_[3] };
int[] x3 = { x[2], x[4], x_[4] };
int[] y3 = { y[2], y[4], y_[4] };
g.fillPolygon(x1, y1, 3);
g.fillPolygon(x2, y2, 3);
g.fillPolygon(x3, y3, 3); // 描边
// g.setColor(Color.BLACK);
// g.drawLine(x[0], y[0], x[2], y[2]);
// g.drawLine(x[0], y[0], x[3], y[3]);
// g.drawLine(x[1], y[1], x[3], y[3]);
// g.drawLine(x[1], y[1], x[4], y[4]);
// g.drawLine(x[2], y[2], x[4], y[4]);
// g.drawLine(x[2], y[2], x[0], y[0]); } public static void main(String[] args) {
new WuJiaoXing();
}
}
import java.util.ArrayList;public class Main { public static void main(String []args){
//求100的阶乘
System.out.println(getBigValues(100));
//用double表求的100阶乘
System.out.println(getDoubleValues(100));
}
//用Double数据类型表示的阶乘值
public static double getDoubleValues(int val){
if(val <= 1){
return 1;
}
return val * getDoubleValues(val-1);
}
//用BigInteger 求100的阶乘
static ArrayList list = new ArrayList();
static{
//初始化ArrayList
list.add(BigInteger.valueOf(1));
}
public static BigInteger getBigValues(int val){
if(val <= 1){
return BigInteger.valueOf(1);
}
for(int i=list.size(); i<=val; i++){
BigInteger firstVal = (BigInteger)list.get(i-1);
BigInteger nextVal = firstVal.multiply(BigInteger.valueOf(i));
list.add(nextVal);
}
return (BigInteger)list.get(val);
}
}