作业1:
package com.mx.test;
import java.util.Scanner;
import java.util.Scanner;
public class Zuoye01 {
private int floor;
public static void main(String args[])
{
System.out.print("请输入金字塔的高度:");
int i,floor;
Scanner sc = new Scanner(System.in);
floor = sc.nextInt();
for(i=0;i<floor;i++)
{
for(int j=0; j<(floor-i); j++)
{//控制空格
System.out.print(" ");
}
for(int t=0; t<(2*i+1); t++)
{//控制打印*号
System.out.print("*");
}
System.out.println("");
}
}
}
private int floor;
public static void main(String args[])
{
System.out.print("请输入金字塔的高度:");
int i,floor;
Scanner sc = new Scanner(System.in);
floor = sc.nextInt();
for(i=0;i<floor;i++)
{
for(int j=0; j<(floor-i); j++)
{//控制空格
System.out.print(" ");
}
for(int t=0; t<(2*i+1); t++)
{//控制打印*号
System.out.print("*");
}
System.out.println("");
}
}
}
作业2:
package com.mx.test;
import java.util.Scanner;
import java.util.Scanner;
public class Zuoye02 {
private int number;
private int number;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("请输入乘法表的数字(1-9):");
int i,number;
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
// TODO Auto-generated method stub
System.out.print("请输入乘法表的数字(1-9):");
int i,number;
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
for (i = 1; i <= number; i++)
{
for(int n = 1; n <= i; n++)
{
System.out.print( i + "x" + n + "=" + i * n + "\t");
}
System.out.println();
}
{
for(int n = 1; n <= i; n++)
{
System.out.print( i + "x" + n + "=" + i * n + "\t");
}
System.out.println();
}
}
}
作业3:
package com.mx.test;
import java.util.Scanner;
import java.util.Scanner;
public class Zuoye03 {
private int length;
public static void main(String args[])
{
System.out.print("请输入数组的高度:");
int i,length;
Scanner sc = new Scanner(System.in);
length = sc.nextInt();
int[][] a = new int [length][length];
for(i=0;i<length;i++)
{
for(int j=0;j<length;j++)
{
if(i==0)
a[i][j]=i+j+1;
else
a[i][j]=(j+1)+i*length;
System.out.print(+a[i][j]+"\t");
}
System.out.println();
}
System.out.println("转置:");
for(i=0;i<length;i++)
{
for(int j=i;j<length;j++)
{
int temp;
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
for(i=0;i<length;i++)
{
for(int j=0;j<length;j++)
System.out.print(a[i][j]+"\t");
System.out.println();
}
}
}
private int length;
public static void main(String args[])
{
System.out.print("请输入数组的高度:");
int i,length;
Scanner sc = new Scanner(System.in);
length = sc.nextInt();
int[][] a = new int [length][length];
for(i=0;i<length;i++)
{
for(int j=0;j<length;j++)
{
if(i==0)
a[i][j]=i+j+1;
else
a[i][j]=(j+1)+i*length;
System.out.print(+a[i][j]+"\t");
}
System.out.println();
}
System.out.println("转置:");
for(i=0;i<length;i++)
{
for(int j=i;j<length;j++)
{
int temp;
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
for(i=0;i<length;i++)
{
for(int j=0;j<length;j++)
System.out.print(a[i][j]+"\t");
System.out.println();
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/de3454ff576bd0c94ed5c221dfde22ad.png)