Shorter version of Java System.out.println() -
is there way shorthand system.out.println()
method?
system.out.println() = short();
so change main method to...
package array; import java.util.random; public class array { public static void main(string args[]) { data(); a(); random(); a(); array(); a(); rows(); a(); system.out.println("average " + average(45,15,15,48,97,45)); } static void a() {system.out.println();} static void data() { int array[] = {1,5,6}; int alength = array.length; system.out.println(" location\tdata"); for(int i=0;i<alength;i++) { system.out.println(" " + + "\t\t" + array[i]); } } static void random() { random rdm = new random(); int freq[] = new int[7]; for(int i=1;i<1000;i++) { ++freq[1+rdm.nextint(6)]; } system.out.println("face\tfrequency"); int frequence = freq.length; for(int face=1;face<frequence;face++) { system.out.println(face+"\t"+freq[face]); } } static void array() { string po[] = {"lala","po","tinkiwinki","disty"}; for(string lala: po) { system.out.print(lala + " "); } system.out.println(); } static void rows() { int arrays[][]= {{1,5,78,15},{45,67},{875,15687,158,4515,23,2,2}}; for(int i=0;i<arrays.length;i++) { for(int j=0;j<arrays[i].length;j++) { system.out.print(arrays[i][j]+"\t"); } system.out.println(); } } static int average(int...numbers) { int total=0; for(int x:numbers) total += x; return total/numbers.length; } } class time { int h, m, s; void settime(int hour,int minute,int second) { h = ((hour>=0 && hour<=24) ? hour : 0); m = ((minute>=0 && minute<=60) ? minute : 0); s = ((second>=0 && second<=60) ? second : 0); }
this main method
public class array { public static void main(string args[]) { a(data()); a(random()); a(array()); a(rows()); a("average " + average(45,15,15,48,97,45));
it prints out this
location data 0 1 1 5 2 6 face frequency 1 154 2 186 3 161 4 168 5 179 6 151 lala po tinkiwinki disty 1 5 78 15 45 67 875 15687 158 4515 23 2 2 average 44
so want a() print newline, what's passed it?
static void a(callable<t> f) { system.out.println(); f.call(); }
i think should it.
if don't want mess callable:
instead of having methods return void , printing, have them return string.
then have take string argument , print newline followed string passed in.
Comments
Post a Comment