javase程序设计上机作业2
2024-09-02 22:22:37
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("程序退出");
}
}
}
最新文章
- 自定义控件之圆形的image
- UIAlertController、UIAlertAction 警告框
- &ldquo;耐撕&rdquo;团队2016.04.12站立会议
- 蓝桥杯 algo_5 最短路 (bellman,SPFA)
- Excel插件类库的设计思路
- 删除所有表数据的sql语句
- Winform-控制边框显示属性
- asp.net中对象的序列化,方便网络传输
- ";Cannot find entry symbol nable-stdcll-fixup; defaulting to 00401000"; 解决方案
- Linux MySQL5.5源码安装
- CABasicAnimation 基本动画
- 1.怎样控制div中的图片居中
- [asp.net core 源码分析] 01 - Session
- pyspider和pyquery总结
- Scala视图界定
- laravel 使用DB 鏈接leftJoin查詢
- js 统计数组中元素的个数
- Java03-Java语法基础(二)运算符
- JDBC连接MySql,配置url报错
- OSS介绍
热门文章
- Python基于机器学习方法实现的电影推荐系统
- split 命令
- nginx设置负载均衡
- Gym-10071A-Queries(树状数组)
- ";TypeError: handler.call is not a function";问题
- 【leetcode】1259.Handshakes That Don&#39;t Cross
- Invalid [xxx] in servlet mapping 、 <;url-pattern>;的匹配规则 、 DefaultServlet介绍
- mongodb .net 版本
- @ApiParam和@RequestHeader接收参数的区别
- php l练习(写着玩)