Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ejercicio4;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author 988699
  13. */
  14. public class Ejercicio4 {
  15. static int i = 1;
  16. /**
  17. * @param args the command line arguments
  18. */
  19.  
  20. public static int sum(int n1, int n2) {
  21. return n1+n2;
  22. }
  23. public static int sum(int n1, int n2, int n3) {
  24. return n1+n2+n3;
  25. }
  26.  
  27. public static int restar(int n1, int n2) {
  28. int res = 0;
  29. if(n2 >= n1) {
  30. res = n2-n1;
  31. }else if(n1 > n2) {
  32. res = n1-n2;
  33. }
  34. return res;
  35. }
  36.  
  37. public static int moltiplication(int n1, int n2) {
  38. return n1*n2;
  39. }
  40.  
  41. public static double divide(int n1, int n2) {
  42. int res = 0;
  43. if(n2 >= n1) {
  44. res = n2/n1;
  45. }else if(n1 > n2) {
  46. res = n1/n2;
  47. }
  48. return res;
  49. }
  50.  
  51. public static void main(String[] args) {
  52. Scanner sc = new Scanner(System.in);
  53. int op;
  54. int n1;
  55. int n2;
  56. int n3;
  57. int op2;
  58. while(i == 1) {
  59. System.out.print("1 - Sumar\n");
  60. System.out.print("2 - Restar\n");
  61. System.out.print("3 - Moltiplicar\n");
  62. System.out.print("4 - Dividir\n");
  63. System.out.print("0 - Salir\n");
  64. System.out.print("Press a button to continue: ");
  65. op = sc.nextInt();
  66.  
  67. switch(op) {
  68. case 1:
  69. System.out.println("2 - to sum 2 number\n");
  70. System.out.println("3 - to sum 3 number\n");
  71. op2 = sc.nextInt();
  72. if(op2 == 2) {
  73. System.out.print("- SUM2 -\n");
  74. System.out.print("Primo numero: ");
  75. n1 = sc.nextInt();
  76. System.out.print("Segundo numero: ");
  77. n2 = sc.nextInt();
  78. System.out.printf("Resultado = %d\n", sum(n1,n2));
  79. }else if (op2 == 3) {
  80. System.out.print("- SUM3 -\n");
  81. System.out.print("Primo numero: ");
  82. n1 = sc.nextInt();
  83. System.out.print("Segundo numero: ");
  84. n2 = sc.nextInt();
  85. System.out.print("Terzero numero: ");
  86. n3 = sc.nextInt();
  87. System.out.printf("Resultado = %d\n", sum(n1,n2,n3));
  88. }else {
  89. System.out.print("Error wrong option\n");
  90. }
  91. break;
  92. case 2:
  93. System.out.print("- RESTAR -\n");
  94. System.out.print("Primero numero: ");
  95. n1 = sc.nextInt();
  96. System.out.print("Segundo numero: ");
  97. n2 = sc.nextInt();
  98. System.out.printf("Resultado = %d\n", restar(n1,n2));
  99. break;
  100. case 3:
  101. System.out.print("- MOLTIPLICATION -\n");
  102. System.out.print("Primero numero: ");
  103. n1 = sc.nextInt();
  104. System.out.print("Segundo numero: ");
  105. n2 = sc.nextInt();
  106. System.out.printf("Resultado = %d\n", moltiplication(n1,n2));
  107. break;
  108. case 4:
  109. System.out.print("- DIVIDE -\n");
  110. System.out.print("Primero numero: ");
  111. n1 = sc.nextInt();
  112. System.out.print("Segundo numero: ");
  113. n2 = sc.nextInt();
  114. System.out.printf("Resultado = %.2f\n", divide(n1,n2));
  115. break;
  116.  
  117. case 0:
  118. System.out.print("Adios.");
  119. i = 0;
  120. break;
  121. }
  122.  
  123. }
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement