Numero mayor y menor de una matriz en java por medio de la comparacion
/** * * @author Gabriel */ import java.io.*; public class ejer3{ public static void main (String[]args)throws IOException{ String nombre; int v[]; v=new int[10]; BufferedReader lectura=new BufferedReader(new InputStreamReader(System.in)); for (int i=0;i<=9;i++){ System.out.println("Ingresa un numero"); nombre=lectura.readLine(); int x=Integer.parseInt(nombre); v[i]=x; } System.out.println ("***Buscando el numero maximo***"); int may; may=v[0]; for (int z=0; z<=9; z++){ if (v [z]>may){ may=v[z]; } } System.out.println ("El numero maximo es : "+may); System.out.println ("***Buscando el numero minimo"); int men; men=v[0]; for (int z=0; z<=9; z++){ if (v [z]<men){ men=v[z]; } } System.out.println ("EL numero minimo es : "+men); } }
Compartir
9 comentarios:
Buena :P me sirvio lo del numero mayor no se me ocurrio como hacerlo.. gracias
ese no es matriz es vector
Si, No es bidimencional
kñl khgikyhilgiiuolja<dlñsjafkcñaklsefcnjABSECfjklaSBHC
A VER LA MATRIZ?? ESO ES UN PUTO VECTOR!
No entiendo porque declaras la variable nombre de tipo String, si el programa te pide que ingreses numeros, no nombres. Podias haber declarado una variable de tipo entera.
//con matriz y numeros aleatorios.
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
int a[][],i,r,c,j;
int mayor=0;
System.out.println("Ingrese valor (Renglon)");
r=teclado.nextInt();
System.out.println("Ingrese valor (Columna)");
c=teclado.nextInt();
a=new int [r][c];
for(i=0;imayor){
mayor=a[i][j];
}
}
}
System.out.println ("El numero maximo es: "+mayor);
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if (a [i][j]<mayor){
mayor=a[i][j];
}
}
}
System.out.println ("El numero menor es: "+mayor);
}
}
Publicar un comentario