Sei sulla pagina 1di 3

# //MATRIZ 1

package pMATRIZ;

import java.util.Scanner;

## public static void main(String[] args) {

Scanner leer=new Scanner(System.in);
int n=0,con=0;
System.out.print("Ingrerse dimencion :");
n=leer.nextInt();
int M[][]=new int [30][30];
con=0;
for(int f=0;f<n;f++)
{
for(int c=0;c<n;c++)
{
if(c>=f)
{ con++;
M[f][c]=con;
}
else
M[f][c]=0;
}
}
for(int f=0;f<n;f++)
{
for(int c=0;c<n;c++)
{
System.out.print( M[f][c] +" ");
}
System.out.println();
}
}

}
//MATRIZ 2
import java.util.Scanner;
public class matriz2 {
public static void main(String[] args) {
Scanner leer=new Scanner(System.in);
int n=0,con=0,con2;
System.out.print("Ingrerse dimencion :");
n=leer.nextInt();
int M[][]=new int [30][30];
con=0;
for(int f=0;f<n;f++)
{ con2=n;
for(int c=0;c<n;c++)
{
if(c==f)
{ con++;
M[f][c]=con;
}
else
{ if(c>f)
{ M[f][c]=M[f][c-1]+con2;
con2--;
}
else
M[f][c]=0;
}
}
}

for(int f=0;f<n;f++)
{
for(int c=0;c<n;c++)
{
System.out.print( M[f][c] +" ");
}
System.out.println();
}

}
MATRIZ3

package pMATRIZ;

import java.util.Scanner;

## public static void main(String[] args) {

int n,con=0,sw=0, mit;
int M[][]=new int[30][30];
Scanner leer=new Scanner(System.in);
System.out.print("Ingrerse dimencion :");
n=leer.nextInt();
sw=0;
mit=n/2;
if(n%2==0)
{
mit=mit-1;
sw=1;
}

for(int f=0;f<n;f++)
{
for(int c=0;c<n;c++)
{
if(c>=con && c<=(n-con-1))
M[f][c]=1;
else
M[f][c]=0;
}
if(f>=mit)
{
if(sw==1)
sw=0;
else
con--;
}
else
con++;
}

for(int f=0;f<n;f++)
{
for(int c=0;c<n;c++)
{
System.out.print( M[f][c] );
}
System.out.println();
}
}