1,杨辉三角算法
public class shuzu4_5 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int[][] array=YangHuiArray(10);//十行十列
printYangHui(array);
}
static int[][] YangHuiArray(int n)
{
int[][] array=new int[n][n];
for(int i=0;i<array.length;i++)
{
for(int j=0;j<=i;j++)
{
if(i==j||j==0)
{
array[i][j]=1;
}
}
if(i>=2)
{
for(int j=1;j<array[i].length;j++)
array[i][j]=array[i-1][j]+array[i-1][j-1];
}
}
return array;
}
static void printYangHui(int [][] array)
{
for(int i=0;i<array.length;i++)
{
for(int j=0;j<=i;j++)
System.out.print(array[i][j]+" ");
System.out.println();
}
}
static void printTwoArray(int [][] array)
{
for(int i=0;i<array.length;i++)
{
for(int j=0;j<array[i].length;j++)
System.out.print(array[i][j]+" ");
System.out.println();
}
}
}
2,统计成绩
import java.util.Scanner;
import java.util.Arrays;
public class shuzu4_5 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner input = new Scanner(System.in);
int a=3;
int b=3;
int name[]=new int[]{1,2,3};//储存编号
String course[]=new String[]{"语文成绩","数学成绩","英语成绩"};
int[][] score=new int[a][b];
int[] sum=new int[a];
double[] avg=new double[a];
String[] content=new String[a];
for(int i=0;i<a;i++){
System.out.println("请输入第"+(i+1)+"个学生的编号:");
Scanner sc=new Scanner(System.in);
name[i]=sc.nextInt();
content[i]=name[i]+"\t\t";
for(int j=0;j<b;j++){
System.out.println("请输入"+course[j]+"的:");
score[i][j]=sc.nextInt();
sum[i]+=score[i][j];
content[i]+=score[i][j]+"\t\t";
}
avg[i]=sum[i]/a; //计算平均分
content[i]+=avg[i]+"\t\t"+sum[i]+"\t\t";
}
System.out.println("学生成绩结果如下");
System.out.println("----------------------------------------------------------------------------------------------------");
System.out.print("学生编号\t\t");
for(int i=0;i<b;i++){
System.out.print(course[i]+"\t\t");
}
System.out.println("平均成绩\t\t总成绩");
for(int i=0;i<a;i++){
System.out.println(content[i]);
}
}
}
3,客车售票
import java.util.Arrays;
import java.util.Scanner;
public class shuzu4_5 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
System.out.println("简单客车售票系统");
System.out.println(" 9排4列的大巴车开始售票");
char arr[][]=new char[9][7];
arr[0]=new char[]{'1','1','1','1'};
arr[1]=new char[]{'1','1','1','1'};
arr[2]=new char[]{'1','1','1','1'};
arr[3]=new char[]{'1','1','1','1'};
arr[4]=new char[]{'1','1','1','1'};
arr[5]=new char[]{'1','1','1','1'};
arr[6]=new char[]{'1','1','1','1'};
arr[7]=new char[]{'1','1','1','1'};
arr[8]=new char[]{'1','1','1','1'};
for(int i=0;i<9;i++){
for(int j=0;j<4;j++){
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
System.out.println("请输入要预定的坐位行号:");
Scanner a=new Scanner(System.in);
int b=a.nextInt();
System.out.println("请输入要预定的坐位列号:");
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
System.out.println("简单客车售票系统");
System.out.println(" 9排4列的大巴车开始售票");
char s[]=new char[]{'0'};
arr[b-1][c-1]=s[0];
for(int e=0;e<9;e++){
for(int f=0;f<4;f++){
System.out.print(arr[e][f]+"\t");
}
System.out.println();
}
}
}