Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3.  
  4. System.out.println("Result of addition = "+ getSum(mapToNum(args)));
  5. System.out.println("Result of multiplication = "+ getMult(mapToNum(args)));
  6. }
  7.  
  8. public static int[] mapToNum(String[] args) {
  9. int[] array = new int [args.length];
  10. for (int i=0; i<array.length; i++) {
  11. array [i] = Integer.parseInt(args[i]);
  12. }
  13. return array;
  14. }
  15.  
  16.  
  17. public static int getSum(int[] array) {
  18. int sum = 0;
  19. for (int i=0; i<array.length; i++) {
  20. sum += array [i];
  21. }
  22. return sum;
  23. }
  24.  
  25. public static int getMult(int[] array) {
  26. int result = 1;
  27. for (int i=0; i<array.length; i++) {
  28. result *= array [i];
  29. }
  30. return result;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement