pablosotol

Clase con metodos

Oct 5th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class ListadoNumeros {
  4.        private int[] numeros;
  5.        
  6.        public ListadoNumeros(){
  7.               numeros=new int[100];
  8.        }
  9.  
  10.        public void Llenar(){
  11.               Random rand=new Random();
  12.               for(int i=0;i<numeros.length;i++){
  13.                   numeros[i]=rand.nextInt(100)+1;
  14. }
  15. }
  16.        public void mostrar(){
  17.               for(int i=0;i<numeros.length;i++){
  18.                   System.out.println(numeros[i]+" ");
  19.        }          
  20.                   System.out.println( );
  21.        }
  22.  
  23.  
  24.       public void ordenar(boolean tipo){
  25.              int aux=0;
  26.              if(tipo==true){
  27.              for(int i=0;i<numeros.length-1;i++){
  28.                  for(int j=0;j<numeros.length;j++){                
  29.                      if(numeros[i]<numeros[j]){
  30.                      aux=numeros[j];
  31.                      numeros[j]=numeros[j+1];
  32.                      numeros[j+1]=aux;  
  33.                      }else{
  34. }
  35. }
  36.              }
  37.              }
  38.       }
  39.      
  40.       public void menorMayor(){
  41.              int aux;
  42.              for(int i=0;i<numeros.length-1;i++){
  43.                  for(int j=i+1;j<numeros.length;j++){
  44.                      if(numeros[i]>numeros[j]){
  45.                         aux=numeros[j];
  46.                         numeros[j]=numeros[j+1];
  47.                         numeros[j+1]=aux;
  48.                      }
  49.                  }
  50.              }
  51.       }
  52.      
  53. }
Advertisement
Add Comment
Please, Sign In to add comment