public static void main(String[] args) {
int sum = factorial_sum(); //定义sum调用factorial_sum()
Systemoutprintln(sum);
}
/
定义计算阶乘的函数,可以在factorial_sum()的()里面加一个参数,由用户输入是到1哪一个数的阶乘和。
即:
factorial_sum(int n){
int sum=0;//和
int num = n;//变量,多少之内的阶乘和
int factorial=1;//阶乘
for(int i=1;i<=num;i++){
factorial = i;//也可以写为 factorial = factorial i;
sum += factorial;
}
return sum;//放回计算结果
}
在数函数中调用使用
即:
Scanner sc = new Scanner(Systemin);
int n = scnextInt();
int sum = factorial_sum(n);
Systemoutprintln(sum);
/
public static int factorial_sum() {
int sum=0;//和
int num = 10;//变量,多少之内的阶乘和
int factorial=1;//阶乘
for(int i=1;i<=num;i++){
factorial = i;//也可以写为 factorial = factorial i;
sum += factorial;
}
return sum;//放回计算结果
}
}
希望对你有用
11<%@ page language="java" pageEncoding="gb2312"%>
<html>
<head>
<title>test</title>
</head>
<body>
<%
int age;
String name;
age=21;
name="测试者";
outprint("你的年龄:"+age+"<br>");
outprint("名字:"+name);
%>
</body>
</html>
2
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="javautilDate"%>
<html>
<head>
<title>test</title>
</head>
<body>
<%
Date mydate=new Date();
%>
当前时间是:<%=mydatetoLocaleString()%><br>
<br>
</body>
</html>
3<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="javautilDate"%>
<html>
<head>
<title>test</title>
</head>
<body>
<%
Date mydate=new Date();
String t="";
int hour=mydategetHours();
if(hour>18&&hour<24){
t="晚上";
}else if(hour>0&&hour<6){
t="凌晨";
}else if(hour>5&&hour<11){
t="上午";
}else if(hour>10&&hour<14){
t="中午";
}else if(hour>13&&hour<19){
t="下午";
}
%>
<font size="5"color=red><%=t%>好!</font>
当前时间是:<%=mydatetoLocaleString()%><br>
<br>
</body>
</html>
具体时间自己改下
4
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="javalangMath"%>
<html>
<head>
<title>test</title>
<%
double i,j,rs;
i=Mathsqrt(20);
j=353535;
rs=2i/j;
%>
</head>
<body>
i是:<%=i%><br>
j是:<%=j%><br>
结果是:<font color=red><%=rs%></font>
</body>
</html>
5
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="javalangMath"%>
<html>
<head>
<title>test</title>
<%!
public double mycal(double a,double b){
double rs;
rs=a2/b;
return rs;
}
%>
</head>
<body>
<%
double i=Mathsqrt(20);
double j=353535;
%>
<font color=red>
i2/j:<%=mycal(i,j)%><br>
52/10:<%=mycal(5,10)%>
</font>
</body>
</html>
运行结果
public static int a(int n){int sum=0;
if (n==0||n==1){
sum = 1;
}else{
sum = na(n-1);
}
return sum;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Systemoutprintln(a(10));
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)