java练习7.16

package com.jx;


public class Array {
private int line = 3;
private int col = 3;
private int [][]a = new int [3][3];
public Array(int a00,int a01,int a02,int a10,int a11,int a12,int a20,int a21,int a22)
{
this.a[0][0] = a00;
this.a[0][1] = a01;
this.a[0][2] = a02;
this.a[1][0] = a10;
this.a[1][1] = a11;
this.a[1][2] = a12;
this.a[2][0] = a20;
this.a[2][1] = a21;
this.a[2][2] = a22;
}
public void changeArray()
{
int temp;
for(int i = 0;i<this.line;i++)
{
for(int j = 0;j<i;j++)
{
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
}
public void printArray()
{
for(int i = 0;i<this.line;i++)
{
for(int j = 0;j<this.col;j++)
{
System.out.print(this.a[i][j]+"  ");
}
System.out.println();
}
}

}



package com.jx;


public class Multiplication {
private int floor;//层数
public Multiplication(int floor){
this.floor = floor;
}
public void print()
{
for(int i = 1;i<=floor;i++)
{
for(int j = 1;j<=i;j++)
{
System.out.print(i+"x"+j+"="+i*j+"    ");
}
System.out.println();
}

}

}



package com.jx;


public class Triangle {
private int floor;   //层数
public Triangle(int floor){
this.floor = floor;
}
public void print()
{
for(int i = 1;i <= floor;i++)
{
for(int j = 1;j<=(2*floor-1);j++)
{
if(j<=(floor-i+1)||j>=(floor+i-1))
System.out.print(" ");
else
System.out.print("*");
}
System.out.println();
}
}

}



package com.jx.test;
import com.jx.*;
public class Test {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Triangle t = new Triangle(7);
t.print();
Multiplication m = new Multiplication(9);
m.print();
Array a = new Array(1,2,3,4,5,6,7,8,9);
a.printArray();
a.changeArray();
a.printArray();
}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值