Documentos de Académico
Documentos de Profesional
Documentos de Cultura
FUNCIONES
// programa para encontrar el minimo de dos valores que ingresan por teclado
import java.io.*;
public class p1
{
public static void main(String args[])throws IOException
{
int a, b;
BufferedReader in;
in = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Ingrese un numero ");
a = Integer.parseInt(in.readLine());
System.out.println("Ingrese otro numero ");
b = Integer.parseInt(in.readLine());
System.out.println("El menor es "+min(a,b));
}
//definicion de la funcion
public static int min(int x, int y)
{
2
Z=x<=y ? x:y;
Esto quiere decir que si x<=y entonces z=x, caso contrario
z=y. En otras palabras es igual a escribir:
If (x<=y) Z=x;
Else
Z =y;
}}
}
System.out.println("La sumatoria de factoriales es "+suma);
}
public static int calcula_factorial_de(int z)
{
int resultado=1;
for(int j=1;j<=z;j++){
resultado=resultado*j;
}
return resultado;
}
}
import java.io.*;
public class matrices
{
public static void main (String [] args) throws IOException
{
int x,y;
BufferedReader k;
k = new BufferedReader (new InputStreamReader (System.in));
do
{
System.out.println (" Dimension de la matriz cuadrada A: ");
x = Integer.parseInt (k.readLine ());
}
while (x <= 0); //nos aseguramos que sea positivo
System.out.println("\n**** Datos para la matriz A ****");
int [][] A = lee_matriz (x);
do
{
System.out.println (" Dimension de la matriz cuadrada B: ");
y = Integer.parseInt (k.readLine ());
}
5