jueves, 13 de octubre de 2011

Operaciones matematicas en Java


Clase Operaciones… Aquí realizamos todos los procesos
package Operaciones;

public class Class {
private int n1;
private int n2;

    public Class(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
 public void setvalor (int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
public int car(){
int r=0,f=1;
for(int i=0;i<n2;i++){r=0;
for(int j=0;j<n1;j++){
r+=f;
}
f=r;
}
return(f);
}
public int bivi(int n1,int n2){
int  i=0;
while(this.n1>=this.n2){
this.n1=this.n1-this.n2;
    i++;
    }
return(i);


}
}

Clase principal… Aquí llamamos las operaciones realizadas en la clase anterior y es donde se va a ejecutar el programa
package Operaciones;

import java.io.*;
public class Pri {
public static InputStreamReader L=new InputStreamReader(System.in);
public static BufferedReader T=new BufferedReader(L);

public static void main(String[] args)throws IOException {

    System.out.println("ingrese la base ");
    int a=Integer.parseInt(T.readLine());
    System.out.println("ingrese la potencia ");
    int b=Integer.parseInt(T.readLine());
    Class car1=new Class(a,b);
    int r=car1.car();
    System.out.println("el resultado es:   "+r);
   
   
     System.out.println("ingrese el divisor ");
    int c=Integer.parseInt(T.readLine());
    System.out.println("ingrese el dividendo ");
    int d=Integer.parseInt(T.readLine());
    car1.setvalor(c,d);
    int f=car1.bivi(c,d);
    System.out.println("el resultado es:   "+f);

   
}
}


Ventana de la ejecucion

No hay comentarios:

Publicar un comentario