JAVA + create HashMap in place of function -
i write following 2 functions want implement functions hashmap ( in place of functions ) how that?
static void somefunction(int count, int[] anarray) { ( int i=0;i<anarray[count];i = + 1) { system.out.print("#"); } system.out.println(""); } static void somefunctionb(int[] anarray , int count, string stringfinal, string sttr) { anarray[count]= stringfinal.replaceall("[^"+sttr+"]", "").length(); } somefunctionb(anarray , count, stringfinal, sttr ); somefunction(count, anarray);
without using functions (apart public static void main(string[] args)
), like:
map<integer, integer> mapthatpretendstobeanarray = new linkedhashmap<integer, integer>(); mapthatpretendstobeanarray.put(0, 17); mapthatpretendstobeanarray.put(1, 5); mapthatpretendstobeanarray.put(2, 1); mapthatpretendstobeanarray.put(3, 319); //somefunction() (int = 0; < mapthatpretendstobeanarray.get(1); i++) { system.out.print("#"); } system.out.println(""); //somefunctionb() mapthatpretendstobeanarray.put(3, "stringfinal".replaceall("[^"+"sttr"+"]", "").length());
but of course, somefunction()
, somefunctionb()
more useful, because let parameterize arguments instead of having pick hard-coded ones in example.
Comments
Post a Comment