Hey hey C.C, let's have fun with abstract methods, well not really. Okay let's go on!
We are going to use an array and create an abstract method to print in "our" own numbers in the array index list, anyways let's check out.
The output will be, note that 0.0 is the empty array index numbers we created from the start. We have only added value in the 5 to the 9. So that's all !!Code:public class abstractmethod { public static void main(String [] arg) { double d[] = new double[10];//We make an array with a index list containing with the numbers of 0-9 func(d,5,9,2.3);//Our mission, d(the array) in index 5 and 9 enter in the value 2.3(BUT, this will not work out of the box, yet !) for(double q : d)//Looping through the array System.out.println(q);//Printing the array's index numbers value one by one. } protected static void func(double x [], int start, int end, double i) {//our abstract method. We start with using the function int start is connected to 5 and ends in 9, double i is the new output of our new array index list for(int y=start-1; y<end; y++)//we loop through the array to copy in the value 2.3 x[y]=i;//connect the whole old array with our new "array"(now it is one) } }
Code:0.0 0.0 0.0 0.0 2.3 2.3 2.3 2.3 2.3 0.0
My only recommendation I have is make your comments easier to read (so they dont scroll off the page).
That what its easier to read.Code:public class abstractmethod { public static void main(String [] arg) { //We make an array with a index list //containing with the numbers of 0-9 double d[] = new double[10]; //Our mission, d(the array) in index 5 and 9 //enter in the value 2.3(BUT, this will not work //out of the box, yet !) func(d,5,9,2.3); //Looping through the array for(double q : d) ////Printing the array's index numbers value one by one. System.out.println(q); } //our abstract method. We start with using the function //int start is connected to 5 and ends in 9, double i is the //new output of our new array index list protected static void func(double x [], int start, int end, double i) { //we loop through the array to copy in the value 2.3 for(int y=start-1; y<end; y++) //connect the whole old array with our new "array" x[y]=i; } }![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks