Tuesday 15 February 2011

Java Main Method Called -



Java Main Method Called -

can , how phone call main method method in java? please explain using code below:

public class arraysandmethods { public void printarray(double[] arr) { int x = public arraysandmethods.main(int[] studgrades); // pass array in main mehthod other methods //int a=main(args[]); (int = 0; < studgrades.lenght; i++) system.out.print(studgrades[i] + " "); }// end of printarray method public static void main(string args[]){ java.util.scanner input = new java.util.scanner(system.in); // input scanner system.out.println("what size of class?"); int n = input.nextint(); double studgrades[] = new double[n]; (int = 0; < studgrades.length;i++) { system.out.println("what grade of pupil #" + (i+1)); studgrades[i] = input.nextdouble(); } // end of loop }// end of main method }//end of class

after edit:

i've figured out except passing in arguments. utilize homecoming value main? , since homecoming value main array, should parameters phone call of main have brackets? should there value between brackets?

public class arraysandmethods { public void printarray(double[] arr) { int x = arraysandmethods.main(double[i] arr);//error paremeters (int = 0; < studgrades.lenght; i++) system.out.print(studgrades[i] + " "); }// end of printarray method public static double[] main(string args[]){// double array java.util.scanner input = new java.util.scanner(system.in); // input scanner system.out.println("what size of class?"); int n = input.nextint(); double[] arr = new double[n];// declare , initialize array have n many elements (int = 0; < arr.length;i++) {// input grades each students system.out.println("what grade of pupil #" + (i+1)); arr[i] = input.nextdouble(); } // end of loop homecoming arr; }// end of main method }// end of class

it considered bad programming practice phone call main method method. can lead whole list of problems such infinite loops, infinite recursion, etc. main method should include high level functionality programme needs operate, want simple can maintain it. kind of "check" inquire can create functionality own separate method? if why not that? if ever need create phone call again, have separate method so.

java methods

No comments:

Post a Comment