日期:2014-05-20  浏览次数:20650 次

编一个程序输出下列数字形式
编一个程序输出下列数字形式:  
n=4      
0   0   0   0  
0   1   1   1  
0   1   2   2    
0   1   2   3

------解决方案--------------------
public class A {
public void printMatrix(int n){
for(int i=0; i <n; i++) {
int j=0;
for(;j <i;j++){
System.out.print(j + " ");
}
for(int m=0; m <n-j; m++) {
System.out.print(j + " ");
}
System.out.println();
}
}
public static void main(String args[]) {
A a = new A();
a.printMatrix(4);
}
}

------解决方案--------------------
public class JuZheng {

/** Creates a new instance of JuZheng */
public JuZheng() {
}
public void juz(int n){
for(int i=0;i <n;i++){
for(int j=0;j <i;j++){
System.out.print(j+ " ");
}
for(int k=0;k <n-i;k++){
System.out.print(i+ " ");
}
System.out.println();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new JuZheng().juz(10);
// TODO code application logic here
}

}

------解决方案--------------------
public class Test30 {
public static void main(String[] args) {
int n = 10;
for(int i=0; i <n; i++) {
for(int j=0; j <n; j++)
System.out.print((i > j ? j : i) + " ");
System.out.println();
}
}
}
------解决方案--------------------
for(int i=0;i <4;i++)
{
for(int j=0;j <4;j++)
System.out.print(i <j?i:j);
System.out.println();
}
------解决方案--------------------
不是传说中的杨辉三角吗?

------解决方案--------------------
public class ShuZi
{
public static void main(String [] args)
{
int n = 4;
System.out.println( "n = "+n);
int a[][]={{0,0,0,0},{0,1,1,1},{0,1,2,2},{0,1,2,3}};
for(int i=0;i <n;i++)
{
System.out.println();
for(int j=0;j <n;j++)
System.out.print(a[i][j]+ " ");

}
}
}
------解决方案--------------------
路过,鄙视一下楼上的.
------解决方案--------------------
public class Test {
public static void main(String[] args) {
int n =5;
for (int i = 0; i < n; i++) {
outJ(n,i);
}
}
private static void outJ(int n,int j){
int temp =0;
for (int i = 0; i < n; i++) {

if(i <=j){
temp =i;
System.out.print(i+ " ");
}
else{
System.out.print(temp+ " ");
}
}
System.out.println( " ");
}
}
------解决方案--------------------
特点不是狠明显。
------解决方案--------------------
旋转二维数组吧!!!!!!!!!!