Ejercicio que realiza la operacion matematica de dividir mediante restas sucesivas el numero de resta es el resultado.
package Packdivi;
import java.io.*;
public class Principal {
public static InputStreamReader Leer= new InputStreamReader (System.in);
public static BufferedReader Teclado = new BufferedReader (Leer);
public static void main(String[] args)throws IOException {
int a,b;
System.out.println("ingrese el dividendo ");
a=Integer.parseInt(Teclado.readLine());
System.out.println("ingrese el divisor ");
b=Integer.parseInt(Teclado.readLine());
Restar Obj= new Restar(a,b);
Obj.Resta();
// TODO code application logic here
}
}
package Packdivi;
public class Restar {
private int divi;
private int dvsor;
public Restar(int divi, int dvsor) {
this.divi = divi;
this.dvsor = dvsor;
}
public void Resta(){
int res=0;
while(divi>=dvsor){
divi=divi-dvsor;
res++;
}
System.out.print(+res);
System.out.print(".");
System.out.print(+divi);
}
}
CLASE PRINCIPAL
package Packdivi;
import java.io.*;
public class Principal {
public static InputStreamReader Leer= new InputStreamReader (System.in);
public static BufferedReader Teclado = new BufferedReader (Leer);
public static void main(String[] args)throws IOException {
int a,b;
System.out.println("ingrese el dividendo ");
a=Integer.parseInt(Teclado.readLine());
System.out.println("ingrese el divisor ");
b=Integer.parseInt(Teclado.readLine());
Restar Obj= new Restar(a,b);
Obj.Resta();
// TODO code application logic here
}
}
CLASE RESTAS
package Packdivi;
public class Restar {
private int divi;
private int dvsor;
public Restar(int divi, int dvsor) {
this.divi = divi;
this.dvsor = dvsor;
}
public void Resta(){
int res=0;
while(divi>=dvsor){
divi=divi-dvsor;
res++;
}
System.out.print(+res);
System.out.print(".");
System.out.print(+divi);
}
}
Publicar un comentario