Clase Operar:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Packoper;
/**
*
* @author danny
*/
public class Operar {
private int n1;
private int n2;
public Operar(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
public int Suma(){
int s;
s=this.n1+this.n2;
return s;
}
public int Resta(){
int s;
s=this.n1-this.n2;
return s;
}
public int Division(){
int s;
s=this.n1/this.n2;
return s;
}
public int Multi(){
int s=0;
for (int i=0;i
s+=this.n1;
}
return s;
}
}
Clase Principal:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Packoper;
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 n1");
a=Integer.parseInt(Teclado.readLine());
System.out.println("Ingrese n2");
b=Integer.parseInt(Teclado.readLine());
int d;
Operar ope= new Operar(a,b);
d=ope.Suma();
System.out.println("suma"+d);
d=ope.Resta();
System.out.println("Resta"+d);
d=ope.Division();
System.out.println("Division"+d);
d=ope.Multi();
System.out.println("Multi"+d);
// TODO code application logic here
}
}
Ejecución:
No hay comentarios:
Publicar un comentario