Vous êtes sur la page 1sur 5

Clase Promedio

1 package promedio;
2
3 public class Promedio {
4
String nombre[]=new String[4];
5
double tiempo[][] = new double[4][4];
6
double prom[]= new double[4];
7
8
double [] CalculaPromedio(double []Prom,double tiempo[][])
9
{
10
for(int fila =0;fila<tiempo.length;fila++)
11
{
12
double suma=0;
13
for(int col=0;col<tiempo[fila].length;col++)
14
{
15
suma = suma + tiempo[fila][col];
16
}
17
Prom[fila]=suma/tiempo[fila].length;
18
}
19
return Prom;
20
}
21
void visualizar(String[]nombre,double[]Prom)
22
{
23
for(int i=0;i<nombre.length;i++)
24
{
25
System.out.println("nombre "+nombre[i]+" Promedio "+Prom[i]);
26
}
27
}
28 }//fin de la clase

Clase TestPromedio
1 package promedio;
2 public class TestPromedio {
3
static double P[] = new double[4];
4
static double PP[][] = {{10,12,15,13},{16,14,13,20},{10,11,9,9},{15,17,18,10}};
5
static String n[] = {"Rojas","Sanchez","Escobar","Contreras"};
6
7
public static void main(String[] args) {
8
Promedio pruebaPromedio = new Promedio();
9
P = pruebaPromedio.CalculaPromedio(P, PP);
10
pruebaPromedio.visualizar(n, P);
11
} //fin del main
12 }//fin de la clase

Resultados
run:
nombre Rojas Promedio 12.5
nombre Sanchez Promedio 15.75
nombre Escobar Promedio 9.75
nombre Contreras Promedio 15.0
BUILD SUCCESSFUL (total time: 0 seconds)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

// Ejerccio suma de filas de una matriz


public class Matriz
{ static int [][] a ={ {1,15,13,4},
{2,14,6,18},
{3,10,9,12},
{4,10,9,22} };
public static void main(String[] args)
{
System.out.println(" matrix 0");
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length;j++)
{ int sun=0;
for(int k=0;k<a[j].length;k++)
{
System.out.print(a[i][k]+";");
sun=sun+a[j][k];
}//fin del for k
System.out.print(" :"+sun);
System.out.println();
}//fin del for j
System.out.println(" matrix "+ (i+1) );
System.out.println();
}//fin del for i
}// fin del main
}//fin de la clase
matrix 0
1;15;13;4; :33
1;15;13;4; :40
1;15;13;4; :34
1;15;13;4; :45
matrix 1
2;14;6;18; :33

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

2;14;6;18; :40
2;14;6;18; :34
2;14;6;18; :45
matrix 2
3;10;9;12; :33
3;10;9;12; :40
3;10;9;12; :34
3;10;9;12; :45
matrix 3
4;10;9;22; :33
4;10;9;22; :40
4;10;9;22; :34
4;10;9;22; :45

1 public class Test {


int varInstancia;
2
static double varStatic;
3
4
int retornoPorValor(int x) {
5
varInstancia=10;
6
varStatic=5;
7
return (5); } // fin del metodo
8
Test retornoPorReferencia1( Test y, int a) {
9
return( new Test()); } // fin del metodo
10
static double RetornoPoValor (EjemploMetodos a ,Test x) {
11
return varStatic;
12
}
13
14 }// fin del metodo Test
15 public class EjemploMetodos {
int varReferencia1;
16
double varStatic1;
17
18
double retornoPorValor() {
19
varStatic1=10;
20
return(10); } // fin del metodo
21
static int retornoStatic() {
22
// varReferencia1=5;
23
return(5); } // fin del metodo
24
EjemploMetodos retornoReferencia() {
25
varStatic1=15;
26
return(new EjemploMetodos()); }// fin del metodo
27

Test retornoReferencia2() {
28
varReferencia1=100;
29
varStatic1=10;
30
return(new Test());
}// fin del metodo
31
32 public static void main(String[] args) {
EjemploMetodos Obj=new EjemploMetodos();
33
// int y=10;
34
Test Obj1=new Test();
35
Obj1.retornoPorValor(5);
36
Obj1.retornoPorReferencia1( Obj1 ,5);
37
//valor de la variable de instancia en el objeto
38
System.out.println(Obj.retornoReferencia().varStatic1);
39
System.out.println(Obj1.retornoPorReferencia1(Obj1,10).varInstancia);
40
}// fin del mtodo main()
41
42 }//fin del la clase EjemploMetodos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

// Ejerccio suma de filas de una matriz


public class Matriz
{ static int [][] a ={ {1,15,13,4},
{2,14,6,18},
{3,10,9,12},
{4,10,9,22} };
public static void main(String[] args)
{
System.out.println(" matrix 0");
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length;j++)
{ int sun=0;
for(int k=0;k<a[j].length;k++)
{
System.out.print(a[i][k]+";");
sun=sun+a[j][k];
}//fin del for k
System.out.print(" :"+sun);
System.out.println();
}//fin del for j
System.out.println(" matrix "+ (i+1) );
System.out.println();
}//fin del for i
}// fin del main
}//fin de la clase

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

matrix 0
1;15;13;4; :33
1;15;13;4; :40
1;15;13;4; :34
1;15;13;4; :45
matrix 1
2;14;6;18; :33
2;14;6;18; :40
2;14;6;18; :34
2;14;6;18; :45
matrix 2
3;10;9;12; :33
3;10;9;12; :40
3;10;9;12; :34
3;10;9;12; :45
matrix 3
4;10;9;22; :33
4;10;9;22; :40
4;10;9;22; :34
4;10;9;22; :45

Vous aimerez peut-être aussi