周二课堂练习

public class Tal {
 private int a;
 public void Draw(int a){
  int j=0;
  int i=0;
  int m=0;
  for(j=0;j<a;j++)
  {
  for(i=0;i<a-j;i++)
  {System.out.print(" ");}
  for(m=0;m<2*j+1;m++)
   System.out.print("*");  
  System.out.println();}
   
  }
 
 public static void main(String[] args) {
  Tal b = new Tal();
  Scanner s = new Scanner(System.in);
  System.out.println("请输入金字塔层数");
  int a = s.nextInt();
  b.Draw(a);
  
 }
}
请输入金字塔层数
10
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************

public class test01 {
 public void Display(int a){
  int i,j;
  int c;
  for(i=0;i<=a;i++){
  for(j=1;j<=i;j++){
   c=i*j;
   System.out.print(i+"*"+j+"="+c+"\t");
   if(j==i)
    System.out.println();
  }
 }
 }
 public static void main(String[] args) {
  test01 a = new test01();
  while(true){
  System.out.println("输入一个1~9的数字");
  Scanner s =new Scanner(System.in);
  int b= s.nextInt();
  if(b>9||b<1)
  {System.out.println("请输入正确数字");}
  else
  a.Display(b);}
 }
}
输入一个1~9的数字
5
1*1=1 
2*1=2 2*2=4 
3*1=3 3*2=6 3*3=9 
4*1=4 4*2=8 4*3=12 4*4=16 
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 
输入一个1~9的数字
public class Change {
 private int[][] a = new int[3][3];
 public void convert(){
  int i;//行
  int j;//列
  int t;
  for(i=0;i<3;i++)
  {for(j=0;j<3;j++)
   {if(i!=j&&i<j)
    {t=a[i][j];
    a[i][j]=a[j][i];
    a[j][i]=t;
    }
    System.out.print(a[i][j]);
    }
  System.out.println();}}
  public static void main(String[] args) {
   int a;
   int b;
   Change c =new Change();
   Scanner s = new Scanner(System.in);
   System.out.println("请输入9个数字");
   for(a=0;a<3;a++)
    for(b=0;b<3;b++)
    {    
    c.a[a][b]=s.nextInt()  ;
   }
   System.out.println("你目前的3X3矩阵是");
   for(int i=0;i<3;i++)
   {for(int j=0;j<3;j++)
   {System.out.print(c.a[i][j]); }
   System.out.println();}  
   System.out.println("转置后的矩阵是");
   c.convert();
  }
 }

请输入9个数字
1
2
3
4
5
6
7
8
9
你目前的3X3矩阵是
123
456
789
转置后的矩阵是
147
258
369


猜你喜欢

转载自blog.csdn.net/qq_40498484/article/details/81063374