Advertisement
Guest User

matharray

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package twentybiteen;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MathArray {
  6.  
  7. static Scanner sc = new Scanner(System.in);
  8.  
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11.  
  12. Math();
  13.  
  14. }
  15.  
  16. public static void Math() {
  17. System.out.println("How long do you want the array to be?");
  18. int size = sc.nextInt();
  19.  
  20. double[] a = new double[size];
  21. double[] b = new double[size];
  22. double[] sum = new double[size];
  23. double[] difference = new double[size];
  24. double[] quotient = new double[size];
  25.  
  26. System.out.println("Enter " + size + " value(s) for the first array.");
  27. for (int i = 0; i < size; i++) {
  28. a[i] = sc.nextDouble();
  29. }
  30.  
  31. System.out.println("Enter " + size + " value(s) for the second array.");
  32. for (int i = 0; i < size; i++) {
  33. b[i] = sc.nextDouble();
  34. }
  35.  
  36. System.out.println("This is the sum of both arrays.");
  37. for (int i = 0; i < size; i++) {
  38. sum[i] = a[i] + b[i];
  39. System.out.println(sum[i]);
  40. }
  41.  
  42. System.out.println("This is the different of both arrays.");
  43. for (int i = 0; i < size; i++) {
  44. difference[i] = a[i] - b[i];
  45. System.out.println(difference[i]);
  46. }
  47.  
  48. System.out.println("This is the different of both arrays.");
  49. for (int i = 0; i < size; i++) {
  50. quotient[i] = a[i] / b[i];
  51. System.out.println(quotient[i]);
  52. }
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement