CS174: OOP - Drills - Printing array with commas

Developed by Professor Tralie and Professor Mongan.


Exercise Goals

The goals of this exercise are:
  1. To declare a public static method to some specification
  2. To do proper array indexing
  3. To use loops in concert with arrays
  4. To use logic inside of a loop
  5. To use the System.out.print method properly
Declare a void method printArray in the ArrayPrinter class. This method should take an array of ints, and it should then print out the elements of the array separated by commas (this is useful, since printing out an array by default in Java just gives its memory address). For example, the array {0,5,2,4} should be printed out as 0, 5, 2, 4. Note how there is no comma or space at the end of the output string.

Enter your Ursinus netid before clicking run. This is not your ID number or your email. For example, my netid is ctralie (non Ursinus students can simply enter their name to get this to run, but they won't get an e-mail record or any form of credit)

Netid
Clicking Run below will check your work and, if it passes, will submit your work automatically. You must be connected to the VPN for submission to be successful! You will receive a copy of your code via e-mail, so you'll know that it was submitted if you receive that e-mail!

ArrayPrinter.java

public class ArrayPrinter { /** TODO: Declare your method here **/ }

Tester.java

public class Tester { public static void main(String[] args) { int[] arr0 = {0, 5, 10, 0, 3, 4}; ArrayPrinter.printArray(arr0); System.out.print("."); int[] arr1 = {0, 0, 1, 2, 4, 3, 4}; ArrayPrinter.printArray(arr1); System.out.print("."); } }
Tester.main(null);

Output