用java语言写一道数学题//这个题难点在大数.因为1000的阶乖十在太大了.所以必须用BigInteger.
//楼上那种算法是不对的.这题看起来简单,其实要比想象中麻烦和难.
import java.math.BigInteger;
import java.util.*;
public class jiesheng{
protected static ArrayList table = new ArrayList();
static{ table.add(BigInteger.valueOf(1));}
public static synchronized BigInteger factorial(int x){
for(int size=table.size();size=x;size++){
BigInteger lastfact= (BigInteger)table.get(size-1);
BigInteger nextfact= lastfact.multiply(BigInteger.valueOf(size));
table.add(nextfact);
}
return (BigInteger) table.get(x);
}
public static void main(String[] args){
System.out.print(factorial(1000));
}
}
这两道题代码怎么写java?创建一个名字为“ReportCard”的类,然后用下边的内容全部替换掉,你会成为全班最亮的仔 。
import java.util.HashMap;
/**
* 学生成绩单
*/
public class ReportCard {
public static void main(String[] args) {
ReportCard reportCard = new ReportCard("张三", "070602213");
reportCard.set("语文", 80.0);
reportCard.set("数学", 59.5);
reportCard.set("英语", 66.0);
reportCard.set("java", 80, 99.0);
reportCard.set("数据库", 80, 66.0);
reportCard.set("毛概", null);
System.out.println(reportCard.getStudentName() + "语文分数:" + reportCard.get("语文"));
System.out.println(reportCard.getStudentName() + "数学考核结果:" + (reportCard.isPassed("数学") ? "合格" : "不合格"));
System.out.println(reportCard.getStudentName() + "期末是否挂科:" + (reportCard.isAllPassed() ? "否" : "是"));
}
// 学生姓名
private String studentName;
// 学生学号
private String studentNumber;
// 成绩单
private HashMapString, CourseResult cards = new HashMap();
public ReportCard() {
}
public ReportCard(String studentName, String studentNumber) {
this.studentName = studentName;
this.studentNumber = studentNumber;
}
public Double get(String courseName){
CourseResult courseResult = cards.get(courseName);
return courseResult == null ? Double.NaN : courseResult.getStudentScore();
}
public void set(String courseName, Double studentScore){
CourseResult courseResult = new CourseResult(courseName, studentScore);
cards.put(courseName, courseResult);
}
public void set(String courseName, double passMark, Double studentScore){
CourseResult courseResult = new CourseResult(courseName, passMark, studentScore);
cards.put(courseName, courseResult);
}
public boolean isPassed(String courseName){
return cards.get(courseName).isPassed();
}
public boolean isAllPassed(){
for(CourseResult cr : cards.values()){
if ( ! cr.isPassed()) {
return false;
}
}
return true;
}
public String getStudentName() {
return studentName;
}
public String getStudentNumber() {
return studentNumber;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
/**
* 课程
*/
class Course{
// 课程名称
protected String courseName;
【java数学题源代码 java 代码题】// 及格分
protected double passMark = 60;
public Course(String courseName, Double passMark) {
this.courseName = courseName;
if ( passMark != null) {
this.passMark = passMark;
}
}
}
/**
* 课程成绩
*/
class CourseResult extends Course{
// 学生成绩
private Double studentScore;
推荐阅读
- 直播运营策略论文,直播运营策划案
- 鸿蒙系统靠近亮屏怎么关闭,鸿蒙系统靠近亮屏怎么关闭应用
- 计算机毕业设计大全,计算机类毕业设计怎么做
- mysql赋予用户建库权限,mysql赋予用户建库权限的命令
- c语言定义一个函数求幂 c语言中求幂的函数
- 玩手机为什么会迟钝呢,为啥玩手机
- 战斗学园横版格斗游戏,战斗学园ez
- js写代码生成工具,js生成器
- c语言函数aver C语言函数不可以单独编译