You are on page 1of 12

Procedimiento Arreglos de una Dimensin Matriz01.

java public class matriz01 { public static void main(String args[]) { int dias_del_mes[]; dias_del_mes=new int[12]; dias_del_mes[0]=31; dias_del_mes[1]=28; dias_del_mes[2]=31; dias_del_mes[3]=30; dias_del_mes[4]=31; dias_del_mes[5]=30; dias_del_mes[6]=31; dias_del_mes[7]=31; dias_del_mes[8]=30; dias_del_mes[9]=31; dias_del_mes[10]=31; dias_del_mes[11]=31; System.out.println("Abril tiene "+ dias_del_mes[3]+"dias"); } }

Matriz02.java public class Matriz02 { public static void main(String args[]) { int dias_del_mes[]={31,28,31,30,31,30,31,31,30,31,30,31}; System.out.println("Abril tiene "+ dias_del_mes[3]+ " dias"); } }

Arreglos Arreglos01.java public class Arreglos01 { public static void main(String args[]) { long[] arreglo; arreglo=new long[100]; int nElementos=0; int j; long busquedaLlave; arreglo[0]=71; arreglo[1]=100; arreglo[2]=46; arreglo[3]=53; arreglo[4]=22; arreglo[5]=75; arreglo[6]=10;

arreglo[7]=64; arreglo[8]=47; arreglo[9]=33; nElementos=10; for(j=0;j<nElementos;j++) System.out.print(arreglo[j]+" "); System.out.println(""); busquedaLlave=53; for(j=0;j<nElementos;j++) if(arreglo[j]==busquedaLlave) break; if(j==nElementos) System.out.println("No se encontro llave "+busquedaLlave); else System.out.println("Se encontro llave "+busquedaLlave); busquedaLlave=64; for(j=0;j<nElementos;j++) if(arreglo[j]==busquedaLlave) break; for(int k=j;k<nElementos-1;k++) arreglo[k]=arreglo[k+1]; nElementos--; for(j=0;j<nElementos;j++) System.out.print(arreglo[j]+ " "); System.out.println(""); } }

GraficoBarrasNotas.java public class GraficoBarrasNotas { public static void main(String args[]) { int array[]= {0,0,0,0,0,0,3,12,6,2,1}; System.out.println("Distribucion de Notas"); for(int contador=0;contador<array.length;contador++) { if(contador==10) System.out.printf("%5d",100); else System.out.printf("%02d-%02d: ",contador*10, contador*10+9); for(int asteriscos=0;asteriscos<array[contador];asteriscos++) System.out.print("*");

System.out.println(); } } }

Arreglos Multidimensionales Matriz05.java public class Matriz05 {

public static void main (String []args) { int a[][] = {{1,2},{3,4}}; int b[][] = {{5,6},{7,8}}; int resultado [][] = new int[2][2]; int i,j; resultado[0][0] = a[0][0]*b[0][0] + a[0][1]*b[1][0]; resultado[0][1] = a[0][0]*b[0][1] + a[0][1]*b[1][1]; resultado[1][0] = a[1][0]*b[0][0] + a[1][1]*b[1][0]; resultado[1][1] = a[1][0]*b[0][1] + a[1][1]*b[1][1]; for( i=0; i<2; i++) { for( j=0; j<2;j++) { System.out.print(resultado[i][j] +" "); } System.out.println(); } } }

Matriz04.java public class Matriz04 { public static void main(String[] args) { int i,j,k=0, filas=0; int b[][] = {{0},{1,2},{3,4,5},{6,7,8,9}}; for( i=0; i<4;i++) { filas++; for( j=0; j< filas;j++) { System.out.print(b[i][j] + " "); } System.out.println(); }

} }

Arreglos de Cadenas Matriz06.java public class Matriz06 { public static void main (String[] args) { if(args[0].equals("-h")) System.out.print("Hola"); else if(args[0].equals("-g")) System.out.print("Adios"); for(int i= 1 ; i<args.length; i++) System.out.print(" "+args[i]); System.out.print("!"); } }

Tarea Complementaria import java.util.*; public class tcomplementariag4 { public static void main(String args[]) { //Declaracin de Variables float[] v1; float[] v2; v1=new float[3]; v2=new float[3]; int i,j; int opcion; Scanner reader= new Scanner(System.in); System.out.println("Ingrese los valores del Vector A"); System.out.println(""); for(i=0;i<3;i++) { System.out.println("Escriba el elemento "+i+":"); v1[i]=reader.nextFloat(); } System.out.print(""); System.out.print("Ingrese los valores del Vector B"); System.out.println(""); for(j=0;j<3;j++) { System.out.println("Escriba el elemento "+j+" : "); v2[j]=reader.nextFloat(); } do{ //Menu System.out.println("******************MENU**************************"); System.out.println("Seleccione la accion a realizar"); System.out.println("1. Calcular producto punto"); System.out.println("2. Calcular producto cruz"); System.out.println("3. Salir"); opcion=reader.nextInt();

switch(opcion) { case 1: productopunto(v1,v2); break; case 2: productocruz(v1,v2); break; case 3: default: System.out.println("Opcion invalida"); } }while(opcion!=4); } public static void productocruz(float[] v1, float [] v2) { float[] w; w=new float[3]; w[0]=v1[1]*v2[2]-v1[2]*v2[1]; w[1]=v1[2]*v2[0]-v1[0]*v2[2]; w[2]=v1[0]*v2[1]-v1[1]*v2[0]; System.out.println(""); System.out.println("El producto cruz de AxB es: "+w[0]+"i"+w[1]+"j"+w[2]+"k"); } public static void productopunto(float[] v1, float[] v2) { float r1; r1=v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]; System.out.println(""); System.out.println("El producto punto de A.B es: "+r1); } } Batera de Prueba 1

Batera de Prueba 2

You might also like