Advertisement
unstoppable7

Untitled

Apr 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. package numero.de.la.suerte;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. /**
  6.  *
  7.  * @author unstoppable
  8.  *
  9.  */
  10. public class NumeroDeLaSuerte {
  11.  
  12.     /**
  13.      * @param args the command line arguments
  14.      */
  15.     public static void main(String[] args) {
  16.  
  17.       File archivo = null;
  18.       FileReader fr = null;
  19.       BufferedReader br = null;
  20.      
  21.       ArrayList<String> digito = new ArrayList<String>();
  22.       ArrayList<String> luck = new ArrayList<String>();
  23.  
  24.       int lineas=0;
  25.            
  26.       try {
  27.          archivo = new File ("datos.txt");
  28.          fr = new FileReader (archivo);
  29.          br = new BufferedReader(fr);
  30.          
  31.          String linea;
  32.          boolean band = false;  
  33.          while( (linea=br.readLine()) != null && lineas != 50 && !band)
  34.          {  
  35.              lineas++;
  36.                      
  37.             String[] temp = linea.split(" ");
  38.            
  39.             if(Integer.parseInt(temp[0]) != -1){
  40.                 digito.add(temp[0]);
  41.                 luck.add(temp[1]);
  42.             }else{
  43.                 band=true;
  44.             }
  45.          }
  46.       }
  47.       catch(Exception e){
  48.          e.printStackTrace();
  49.       }finally{
  50.          try{                    
  51.             if( null != fr ){  
  52.                fr.close();    
  53.             }                  
  54.          }catch (Exception e2){
  55.             e2.printStackTrace();
  56.          }
  57.       }  
  58.                
  59.         String conv, resultado="";
  60.         int cont=0;
  61.         int mayor=0;
  62.         System.out.println("Salida");
  63.         for (int i = 0; i < digito.size(); i++)
  64.         {
  65.             conv="";
  66.             mayor=0;
  67.            
  68.             for (int j = 2; j < 10; j++)
  69.             {
  70.                 cont=0;
  71.                
  72.                 conv = Integer.toString((Integer.parseInt(digito.get(i))), j);
  73.                
  74.                 for (int k = 0; k < conv.length(); k++)
  75.                 {
  76.                     if(conv.charAt(k) == luck.get(i).charAt(0)){
  77.                         cont++;
  78.                         if(cont >= mayor){
  79.                             mayor = cont;
  80.                             resultado = conv;
  81.                         }
  82.                        
  83.                     }
  84.                    
  85.                 }
  86.             }        
  87.             System.out.println(resultado);
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement