CS174: OOP - Drills - Printing array with commas
Developed by Professor Tralie and Professor Mongan.
Exercise Goals
The goals of this exercise are:- To declare a public static method to some specification
- To do proper array indexing
- To use loops in concert with arrays
- To use logic inside of a loop
- To use the
System.out.print
method properly
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 |
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);