标签:alt 设计 else 设计思想 static http pad input logs
课程设计1
设计思想:先求出各个数的阶乘,然后做乘除法
程序流程图如下
输入两个数 |
计算两个数以及他们差的阶乘 |
计算结果,输出 |
import java.util.Scanner;
public class gaga
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Cnk,输入n,输入k");
int n=in.nextInt();
int k=in.nextInt();
int sum=1;
for (int i=1;i<=n;i++)
{
sum=sum*i;
}
int summ=1;
for(int y=1;y<=k;y++)
{
summ=summ*y;
}
int x=n-k;
int summm=1;
for (int l=1;l<=x;l++)
{
summm=summm*l;
}
int su=summm*summ;
double s=sum/su;
System.out.println("结果是"+s);
}
}
课程设计2
import java.util.Scanner;
public class lala
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Cnk,输入n,输入k");
int n=in.nextInt();
int k=in.nextInt();
int sum=1;
for (int i=1;i<=n;i++)
{
sum=sum*i;
}
int summ=1;
for(int y=1;y<=k;y++)
{
summ=summ*y;
}
int x=n-k;
int summm=1;
for (int l=1;l<=x;l++)
{
summm=summm*l;
}
int su=summm*summ;
double s=sum/su;
System.out.println("结果是"+s);
int sum=1;
for (int i=1;i<=n-1;i++)
{
sum=sum*i;
}
int summ=1;
for(int y=1;y<=k-1;y++)
{
summ=summ*y;
}
int v=n-k;
int summm=1;
for (int l=1;l<=v;l++)
{
summm=summm*l;
}
int o=summm*summ;
double w=sum/o;
System.out.println("结果是"+w);
int sum=1;
for (int i=1;i<=n-1;i++)
{
sum=sum*i;
}
int summ=1;
for(int y=1;y<=k;y++)
{
summ=summ*y;
}
int c=n-k;
int summm=1;
for (int l=1;l<=c;l++)
{
summm=summm*l;
}
int u=summm*summ;
double j=sum/u;
System.out.println("结果是"+j);
}
}
汉诺塔问题
import java.util.Scanner;
public class hannuota
{
public static void move(char x,char y)
{
System.out.printf("%c->%c", x,y);
System.out.println();
}
public static void hannuota(int n,char one,char two,char three)
{
if(n==1)
move(one, three);
else
{
hannuota(n-1, one, three, two);
move(one, three);
hannuota(n-1, two, one, three);
}
}
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
System.out.println("请输入汉诺塔的个数:");
int a =input.nextInt();
System.out.println("移动步骤:");
hannuota(a, ‘x‘,‘y‘,‘z‘);
}
}
标签:alt 设计 else 设计思想 static http pad input logs
原文地址:http://www.cnblogs.com/liuzhaowei/p/7662777.html