GreysitoErPutoAmo

EJERCICIO 3 RECURSIVIDAD JAVA

Apr 14th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package ejercicio1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DivRestas {
  6.  
  7.    
  8.     public static void main(String[] args) {
  9.        
  10.     int a=0;
  11.     int b=0;
  12.     int cont=0;
  13.     int resto=0;
  14.    
  15.     Scanner entrada = new Scanner(System.in);
  16.    
  17.     System.out.println("Introduce a: ");
  18.     a=entrada.nextInt();
  19.     System.out.println("Introduce b: ");
  20.     b=entrada.nextInt();
  21.    
  22.     if (a==0 || b==0)
  23.         System.out.println("No se puede dividir por 0");
  24.     else{
  25.         while (a>=b){
  26.             a=a-b;
  27.             cont++;
  28.         }
  29.         resto=a;
  30.         System.out.println("El resultado es: "+cont);
  31.         System.out.println("El resto es:"+resto);
  32.        
  33.     }
  34.        
  35.  
  36.     }
  37.  
  38. }
Add Comment
Please, Sign In to add comment