Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. //b. Write the definition of the method doubleArray that initializes the elements of beta to two times the corresponding elements of alpha.
  4. public class Testing_arrays {
  5.  
  6. static Scanner console = new Scanner(System.in
  7. );
  8.  
  9. public static void main(String[] args) {
  10.  
  11. int [] beta = new int[20];
  12. int [] gamma = {11, 13, 15, 17};
  13.  
  14. int [] alpha = new int[20];
  15. int i, j;
  16.  
  17. System.out.println("Enter twenty values.");
  18.  
  19. inputArray(alpha);
  20. doubleArray(beta);
  21.  
  22.  
  23. System.out.println("The value of array [2] is " + alpha[2]);
  24. System.out.println("The value of array beta [2] is "+ beta[2]);
  25.  
  26.  
  27. public int inputArray(int[] infoArray)
  28. {
  29. for (i = 0; i < infoArray.length; i++)
  30. {
  31. infoArray[i] = console.nextInt();
  32. }
  33.  
  34. }
  35. public int doubleArray(int[] infoDouble)
  36. {
  37. for (i = 0; i < alpha.length; i++)
  38. infoDouble[i] = alpha[i]*2;
  39. }
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement