fork download
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4. public static void main (String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. System.out.println("Informe dois valores: ");
  7. Calculadora calc = new Calculadora(sc.nextDouble(), sc.nextDouble());
  8. System.out.println(calc.soma());
  9. System.out.println(calc.subtracao());
  10. System.out.println(calc.multiplicacao());
  11. System.out.println(calc.divisao());
  12. }
  13. }
  14.  
  15. class Calculadora {
  16. protected double x;
  17. protected double y;
  18.  
  19. Calculadora(double x, double y) {
  20. this.x = x;
  21. this.y = y;
  22. }
  23. double soma() {
  24. return x + y;
  25. }
  26. double subtracao() {
  27. return x - y;
  28. }
  29. double multiplicacao() {
  30. return x * y;
  31. }
  32. double divisao() {
  33. return x / y;
  34. }
  35. }
  36.  
  37. //https://pt.stackoverflow.com/q/254244/101
Success #stdin #stdout 0.12s 37088KB
stdin
5
8
stdout
Informe dois valores: 
13.0
-3.0
40.0
0.625