package javaxgp.teacher.test;

 import java.util.Scanner;

 public class Demo3 {
public static void main(String[] args) {
/**
* 考试等级
*/
// method1();
/**
* 杨辉三角
* 方法一:使用通项公式
* (n!/((n-m)!*m!)
*/
// method2();
/**
* 杨辉三角
* 方法二:使用递推公式
*/
method3(); } private static void method3() {
/**
* 杨辉三角
* 方法二:使用递推公式
*/
int[] a = new int[11];
//定义头上的数
int num = 1;
//循环10列
for (int i = 1; i <= 10; i++) {
//每行i个元素
for (int j = 1; j <= i; j++) {
//定位到每个元素,并保存
int c = a[j];
//修改值
a[j] = num + c;
num = c;
System.out.print(a[j] + "\t");
}
System.out.println();
}
} private static void method2() {
/**
* 杨辉三角
* 方法一:使用通项公式
* (n!/((n-m)!*m!)
*/
int x = 10;
for (int n = 1; n < x; n++) {
for (int m = 1; m <= n; m++) {
System.out.print((fun(n) / (fun(n - m) * fun(m))) + "\t");;
}
System.out.println();
}
} /**
* 计算阶乘的函数
* @param x
* @return
*/
private static int fun(int x) {
int r = 1;
if (x < 2) return r;
for (int i = 2; i <= x; i++){
r = r * i;
}
return r;
} private static void method1() {
/**
* 考试等级
*/
Scanner scanner = new Scanner(System.in);
int num = 0;
try {
while(true) {
System.out.println("请输录考试成绩(输录q键退出程序):");
num = scanner.nextInt();
if(num >= 90 && num <= 100) {
System.out.println("A");
}else if(num >= 80 && num <90) {
System.out.println("B");
}else if(num >= 70 && num < 80) {
System.out.println("C");
}else if (num >= 60 && num < 70) {
System.out.println("D");
}else if(num < 60 && num >= 0) {
System.out.println("E");
}else {
System.out.println("你输入的成绩有误,请重新输录");
}
}
}catch (Exception e) {
System.out.println("程序退出");
}
}
}

最新文章

  1. 自定义控件之圆形的image
  2. UIAlertController、UIAlertAction 警告框
  3. &ldquo;耐撕&rdquo;团队2016.04.12站立会议
  4. 蓝桥杯 algo_5 最短路 (bellman,SPFA)
  5. Excel插件类库的设计思路
  6. 删除所有表数据的sql语句
  7. Winform-控制边框显示属性
  8. asp.net中对象的序列化,方便网络传输
  9. &quot;Cannot find entry symbol nable-stdcll-fixup; defaulting to 00401000&quot; 解决方案
  10. Linux MySQL5.5源码安装
  11. CABasicAnimation 基本动画
  12. 1.怎样控制div中的图片居中
  13. [asp.net core 源码分析] 01 - Session
  14. pyspider和pyquery总结
  15. Scala视图界定
  16. laravel 使用DB 鏈接leftJoin查詢
  17. js 统计数组中元素的个数
  18. Java03-Java语法基础(二)运算符
  19. JDBC连接MySql,配置url报错
  20. OSS介绍

热门文章

  1. Python基于机器学习方法实现的电影推荐系统
  2. split 命令
  3. nginx设置负载均衡
  4. Gym-10071A-Queries(树状数组)
  5. &quot;TypeError: handler.call is not a function&quot;问题
  6. 【leetcode】1259.Handshakes That Don&#39;t Cross
  7. Invalid [xxx] in servlet mapping 、 &lt;url-pattern&gt;的匹配规则 、 DefaultServlet介绍
  8. mongodb .net 版本
  9. @ApiParam和@RequestHeader接收参数的区别
  10. php l练习(写着玩)