zoukankan      html  css  js  c++  java
  • javase程序设计上机作业2

      1 package javaxgp.teacher.test;
      2 
      3 import java.util.Scanner;
      4 
      5 public class Demo3 {
      6     public static void main(String[] args) {
      7         /**
      8          * 考试等级
      9          */
     10 //        method1();
     11         /**
     12          * 杨辉三角
     13          * 方法一:使用通项公式
     14          *      (n!/((n-m)!*m!)
     15          */
     16 //        method2();
     17         /**
     18          * 杨辉三角
     19          * 方法二:使用递推公式
     20          */
     21         method3();
     22 
     23     }
     24 
     25     private static void method3() {
     26         /**
     27          * 杨辉三角
     28          * 方法二:使用递推公式
     29          */
     30         int[] a = new int[11];
     31         //定义头上的数
     32         int num = 1;
     33         //循环10列
     34         for (int i = 1; i <= 10; i++) {
     35             //每行i个元素
     36             for (int j = 1; j <= i; j++) {
     37                 //定位到每个元素,并保存
     38                 int c = a[j];
     39                 //修改值
     40                 a[j] = num + c;
     41                 num = c;
     42                 System.out.print(a[j] + "	");
     43             }
     44             System.out.println();
     45         }
     46     }
     47 
     48     private static void method2() {
     49         /**
     50          * 杨辉三角
     51          * 方法一:使用通项公式
     52          *      (n!/((n-m)!*m!)
     53          */
     54         int x = 10;
     55         for (int n = 1; n < x; n++) {
     56             for (int m = 1; m <= n; m++) {
     57                 System.out.print((fun(n) / (fun(n - m) * fun(m))) + "	");;
     58             }
     59             System.out.println();
     60         }
     61     }
     62 
     63     /**
     64      * 计算阶乘的函数
     65      * @param x
     66      * @return
     67      */
     68     private static int fun(int x) {
     69         int r = 1;
     70         if (x < 2) return r;
     71         for (int i = 2; i <= x; i++){
     72             r = r * i;
     73         }
     74         return r;
     75     }
     76 
     77     private static void method1() {
     78         /**
     79          * 考试等级
     80          */
     81         Scanner scanner = new Scanner(System.in);
     82         int num = 0;
     83         try {
     84             while(true) {
     85                 System.out.println("请输录考试成绩(输录q键退出程序):");
     86                 num = scanner.nextInt();
     87                 if(num >= 90 && num <= 100) {
     88                     System.out.println("A");
     89                 }else if(num >= 80 && num <90) {
     90                     System.out.println("B");
     91                 }else if(num >= 70 && num < 80) {
     92                     System.out.println("C");
     93                 }else if (num >= 60 && num < 70) {
     94                     System.out.println("D");
     95                 }else if(num < 60 && num >= 0) {
     96                     System.out.println("E");
     97                 }else {
     98                     System.out.println("你输入的成绩有误,请重新输录");
     99                 }
    100             }
    101         }catch (Exception e) {
    102             System.out.println("程序退出");
    103         }
    104     }
    105 }
  • 相关阅读:
    学习 Linux 几点忠告【转载】
    游侠更新仙剑全系列免CD补丁(支持WIN7 SP1)【转载】
    更改数据库对象所有者
    数据库 行列相互转化
    JQuery计时器
    js操作cookies
    利用自定义DataTable来重画数据集的用法
    asp.net mvc 从客户端中检测到有潜在危险的 Request.Form 值的解决方法
    CS144 Lab
    CS231n Assignment #2
  • 原文地址:https://www.cnblogs.com/xgp123/p/11606332.html
Copyright © 2011-2022 走看看