fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // Declare an array of 10 integers
  13. int[] arrNumbers = new int[10];
  14.  
  15. // Declare a character array with an initialization list
  16. char[] arrInitials = {'a', 'b', 'c', 'd'};
  17.  
  18.  
  19.  
  20. // Store few values in array
  21. arrNumbers[0] = 12;
  22. arrNumbers[5] = 30;
  23.  
  24. // Display the contents of the character array
  25. //Arrays.toString(arrInitials);
  26. //Arrays.toString(arrNumbers);
  27.  
  28. // Method Call: To display to contents of the array
  29. display(arrNumbers);
  30.  
  31. //Method Call: To update the contents of the array by 2
  32. updateArray(arrNumbers);
  33. display(arrNumbers);
  34. }
  35.  
  36. /*
  37. Method: To display the contents of the array
  38. Parameter: Array of integers
  39. Return: void
  40. */
  41. public static void display(int[] num) {
  42. // For-each loop
  43. for(int n: num) {
  44. System.out.println(n);
  45. }
  46. }
  47.  
  48. /* Method: Update array contents
  49. Parameter: Integer array
  50. Return: void
  51. */
  52. public static void updateArray(int[] num) {
  53. // for loop to traverse across the array
  54. for(int i = 0; i < num.length; i++) {
  55. num[i] = num[i] + 2;
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
Success #stdin #stdout 0.04s 4575232KB
stdin
test1 
stdout
12
0
0
0
0
30
0
0
0
0
14
2
2
2
2
32
2
2
2
2