求两道简单的java代码:1. 编写一个程序,要求在运行时,输入一个数字n,程序运行后,直接输出n!的结果
最好能够带上运行界面的截图,谢谢 展开
第一题
import java.util.Scanner;
public class First
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("请输入一个数字");
int n=in.nextInt();
System.out.println(n+"的阶乘是:"+factorial(n));
}
public static int factorial(int m)
{
if(m==1)
return(1);
else
return(factorial(m-1)*m);
}
}
第二题
import java.util.Scanner;
public class Second
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("请输入圆的半径:");
double R=in.nextDouble();
yuan g=new yuan(R);
System.out.println("圆的周长是:"+g.perimeter());
System.out.println("圆的面积是:"+g.area());
System.out.println("请输入正方形的边长:");
double B=in.nextDouble();
zhengfangxing z=new zhengfangxing(B);
System.out.println("正方形的周长是:"+z.perimeter());
System.out.println("正方形的面积是:"+z.area());
}
}
class yuan extends shape
{
final double PI=3.1415926;
double r,area,perimeter;
public yuan(double R)
{
r=R;
}
public double area()
{
area=PI*Math.pow(r,2.0);
return area;
}
public double perimeter()
{
perimeter=2*PI*r;
return perimeter;
}
}
class zhengfangxing extends shape
{
double l,area,perimeter;
public zhengfangxing(double L)
{
l=L;
}
public double area()
{
area=l*l;
return area;
}
public double perimeter()
{
perimeter=4*l;
return perimeter;
}
}
abstract class shape
{
public abstract double area();
public abstract double perimeter();
}
demo:
xmlHttp.get("password").toString() 得到password的值
document.getElementById('写入层的id').innerHTML='xmlHttp.get("password").toString() ';
{
float w,h;
static float area;
static float perimeter;
public text(float w,float h)
{
this.w=w;
this.h=h;
}
public static void resualt(float w)
{
area=w*w;
perimeter=4*w;
System.out.println("正方形的边长是:"+w);
System.out.println("面积是:"+area);
System.out.println("周长是:"+perimeter);
}
public static void resualt(float w,float h)
{
area=w*w;
perimeter=4*w;
System.out.println("长方形的长是:"+w+"长方形的长是:"+h);
System.out.println("面积是:"+area);
System.out.println("周长是:"+perimeter);
}
public static void main(String argv[])
{
resualt(4);
resualt(3,4);
resualt(4,6);
}
}
{
public static void main(String args[])
int n=Integer.parseInt(args[0]);
int m=0;
for(int i=1;i<=n;i++)
{
m=m*n;
}
System.out.println(m+"");
}
十分感谢。。。。可是第二题呢,还要运行结果的截图。。。