扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
public class array{
创新互联是一家集网站建设,桂平企业网站建设,桂平品牌网站建设,网站定制,桂平网站建设报价,网络营销,网络优化,桂平网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
public static void main(String[] arg){
for(int i=0;i4;i++){
for(int j=1;j=4;j++){
System.out.print(i*4+j+" ");
}
System.out.println("");
}
}
}
}
看看 怎么样!!
public class Matrix {
// 表示行和列
private int mRow, mColumn;
// 构造方法
public Matrix(int row, int column) {
mRow = row;
mColumn = column;
}
// 获取0-20随机数
private int random() {
double random1 = Math.random();// 这个Math类的方法可以获取0.0-1.0之间的随机数
double random2 = random1 * 20; // 0.0 - 20.0
return (int) random2;
}
// 创建矩阵
private void createMatrix() {
int totalCount = mRow * mColumn; // 总共有那么多
for (int count = 1; count = totalCount; count++) {
int number = random();// 上面的方法
System.out.print(number 10 ? "0" + number : number); // 输出数字,如果数字小于10,前面加0补全两位
System.out.print(" "); // 分隔符,随便填
if (count % mRow == 0) {
System.out.println(); // 换行
}
}
}
public static void main(String[] args) {
Matrix matrix = new Matrix(3, 5); // 几行几列传进去
matrix.createMatrix();
}
}
为了经验我也是蛮拼的了
不罗嗦直接给你个代码,注释看不懂就问,改变东西的话,就换arr[]里面的东西就行
public class juzheng {
public static void main(String args[]){
int arr[] = {4,2,3,7,8};//定义数组内容
int count;//计数器
int length = arr.length;//数组的长度
for(int i = 0 ;i length;i++)
{
count =0;
for(int j = i ; count length ; count++,j++){
if(jlength-1)
j=0;
System.out.print(arr[j]+"\t");
}
System.out.println();
}
}
}
public class Matrix {
private int m, n;
private double[][] matrix;
public Matrix(int m, int n) {
this.n = n;
this.m = m;
if (n == 0 || m == 0) {
throw new RuntimeException();
}
matrix = new double[m][n];
}
public void init(double... value) {
if (value.length != m * n) {
throw new RuntimeException();
}
for (int i = 0, a = 0; i m; i++) {
for (int j = 0; j n; j++) {
matrix[i][j] = value[a];
a++;
}
}
}
public Matrix mul(Matrix x) {
if (n != x.m) {
throw new RuntimeException();
}
Matrix c = new Matrix(n, x.m);
for (int i1 = 0; i1 m; i1++) {
for (int i3 = 0; i3 x.n; i3++) {
for (int i2 = 0; i2 n; i2++) {
c.matrix[i1][i3] += matrix[i1][i2] * x.matrix[i2][i3];
}
}
}
return c;
}
public String toString() {
StringBuffer s = new StringBuffer();
for (int i = 0; i m; i++) {
for (int j = 0; j n; j++) {
s.append(matrix[i][j] + " ");
}
s.append("\n");
}
return s.toString();
}
public static void main(String[] args) {
Matrix a = new Matrix(2, 2);
Matrix b = new Matrix(2, 2);
a.init(new double[] { 1, 7, 8, 3 });
b.init(new double[] { 2, 5, 6, 4 });
Matrix c = a.mul(b);
System.out.println(c);
}
}
public class Egg{
public static void main(String[] args){
int[][] arr = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25}
};
int sum1 = 0;
for(int i = 0; i arr.length; i++){
sum1 += arr[i][i];
}
int sum2 = 0;
for(int i = arr.length - 1; i = 0; i--){
sum2 += arr[arr.length - 1 - i][i];
}
System.out.printf("sum1 = %d, sum2 = %d", sum1, sum2);
}
}
public class TestMatrix {
public static void main(String[] args){
int[][] a = {{2,4,1,4},{3,4,5,6},{0,1,2,3},{5,3,9,8},{1,2,3,4}};
int min = a[0][0];
int max = a[0][0];
int minrow = 0;
int mincol = 0;
int maxrow = 0;
int maxcol = 0;
for(int i = 0;i 5;i++){
for(int j = 0;j 4;j++){
if(a[i][j] = min){
min = a[i][j];
minrow = i;
mincol = j;
}
if(a[i][j] max){
max = a[i][j];
maxrow = i;
maxcol = j;
}
}
}
System.out.println("Min is:" + min + " Row is:" + minrow + " col is:" + mincol);
System.out.println("Max is:" + max + " Row is:" + maxrow + " col is:" + maxcol);
}
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流