Professional Documents
Culture Documents
Composición
AGREGACION COMPOSICIÒN
BIDIMENSIONALES UNIDIMENSIONALES
ARREGLO
BIDIMENSIONALES:
Se define como un conjunto de datos del
mismo tipo que están organizados en dos
o mas columnas y uno o mas renglones
1) tipodato nomtabla[][]= new
tipodato[reng][col];
Ejemplo:
int calif[][]=new int[3][4];
double ingresos[][]= new double[3][4];
Declaración Arreglos Bidimensionales
Al igual que en los arrays unidimensionales o
vectores, se crean con declaraciones type y var
y deben ser de tipo ordinales o subrango. Se
deben indicar: • El nombre del array • Tipo del
array • Rango permitido • Ejemplo: Type Tabla =
array [1..25,1..4] of real; Var Grados : Tabla; •
Para localizar o almacenar un valor en el array
se deben especificar dos posiciones o
subíndices, uno para la fila y otro para la
columna.
ARREGLO UNIDIMENSIONALES
Antes de poder usar un arreglo debemos
declararlo mediante la forma general: Donde:
tipo, declara el tipo de cada elemento del
mismo. nombre variable, es el nombre del
array. tamaño, indica el número de elementos
que tendrá el array.
Ejemplo:
Tipo int:intpago [8]
Float notas[17]
Char letras[28]
Double precios[20];
EJEMPLO 1:
package ejemplo;
import java.util.*;
import java.util.Scanner;
public class programa {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList arreglo =new ArrayList ();
Scanner entrada=new Scanner (System.in);
String opc,opc1,opc2;
//ingrese el mensaje manualmente
System.out.println(" \nINGRESE EL MENSAJE");
opc=entrada.next();
opc1=entrada.next();
opc2=entrada.next();
//datos quemados
String resul ="";
arreglo.add("HOLA");
arreglo.add("COMO");
arreglo.add("ESTAN");
arreglo.add("ESTE");
arreglo.add("ES");
arreglo.add("UN");
arreglo.add("EJEMPLO");
arreglo.add("DE");
arreglo.add("ARRAYLIST");
//para desplegar los mensajes
arreglo.add("\n"+opc);
arreglo.add(opc1);
arreglo.add(opc2);
for (Iterator i = arreglo.iterator();i.hasNext();){
resul=resul + " " + i.next();
}
System.out.print(resul);
}
}
package ejercicio;
import java.util.Scanner;
public class principal {
void imprime(operaciones metodos){
System.out.println("NOMBRE : " + metodos.getnombre());
System.out.println("APELLIDO : " + metodos.getapellido());
System.out.println("DIA : " + metodos.getdia());
System.out.println("MES : " + metodos.getmes());
System.out.println("AÑO : " + metodos.getaño());
System.out.println("EDAD : " + metodos.getaño_actual());
}
public static void main(String[] args) {
String nombre;
String apellido;
int dia, mes,año;
try{
Scanner entrada=new Scanner(System.in);
System.out.println("***********INGRESE NOMBRE***********:");
nombre= entrada.next();
System.out.println("**********INGRESE APELLIDO**********:");
apellido= entrada.next();
System.out.println("************INGRESE DIA*************:");
dia= entrada.nextInt();
System.out.println("************INGRESE MES*************:");
mes= entrada.nextInt();
System.out.println("************INGRESE AÑO*************:");
año= entrada.nextInt();
principal prog = new principal( );
operaciones promedio;
promedio = new operaciones(nombre,apellido,dia,mes,año);
prog.imprime(promedio);
}
catch(Exception e){
System.out.println(e);
}
}
}
package ejercicio;
public class operaciones {
int dia;
int mes;
int año;
int año_1 = 2012;
int dia1 = 08,mes1 = 02,año1 = 2012;
String nombre;
String apellido;
operaciones(String nombre,String apellido, int dia, int mes, int año)
{
this.nombre = nombre;
this.apellido = apellido;
this.dia = dia;
this.mes = mes;
this.año = año;
año1=año1-año;
}
void setdia(int d)
{
dia = d;
}
int getdia()
{
return dia;
}
void setmes(int m)
{
mes = m;
}
int getmes()
{
return mes;
}
void setaño(int a)
{
año = a;
}
int getaño()
{
return año;
}
void setnombre(String nom)
{
nombre = nom;
}
String getnombre()
{
return nombre;
}
void setapellido(String ap)
{
apellido = ap;
}
String getapellido()
{
return apellido;
}
void setaño1(int a1)
{
año1 = a1;
}
int getaño_actual()
{
return año1;
}
}