Wallcroft

Untitled

Jan 11th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.  
  2. public class adivinar2 {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.         int numeroAdivinar;
  7.         int numeroComparar;
  8.          short contador;
  9.          int cifrasAdivinar= 0;
  10.          int bandera=0;
  11.          int nDesAdivinar;
  12.        
  13.         System.out.println("Introduzca el primer numero");
  14.         numeroAdivinar=Leer.datoInt();
  15.         nDesAdivinar=numeroAdivinar;
  16.         for ( contador=1 ; contador<=10; contador++){
  17.             System.out.println("Introduzca el segundo numero");
  18.             numeroComparar=Leer.datoInt();
  19.             if(numeroAdivinar==numeroComparar){
  20.              contador=10;
  21.              bandera=1;
  22.             }else{
  23.                
  24.                
  25.                 while(  nDesAdivinar!=0){  
  26.                
  27.                     nDesAdivinar = nDesAdivinar/10;
  28.                     numeroComparar = numeroComparar/10;
  29.                     if(numeroComparar== nDesAdivinar){
  30.                         cifrasAdivinar=cifrasAdivinar+1;
  31.                     }
  32.                      
  33.                 }
  34.                 System.out.println("Has introducido un total de: "+cifrasAdivinar+" dígitos");
  35.        
  36.         }
  37.                
  38.         }
  39.         if(bandera==1){
  40.             System.out.println("Has acertado todas las cifras");
  41.         }
  42.            
  43.        
  44.          
  45.        
  46.        
  47.          
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment