Java Basics - Passing Arrays to Methods

preview_player
Показать описание
This video shows two code examples that demonstrate how arrays can be passed to a method.
Рекомендации по теме
Комментарии
Автор

the sound of the clattering of keys on your keyboard is highly satisfying. it's so fascinating to listen to.

markganus
Автор

I really like your videos. You break down the parts of what the code needs and that is what I was looking for. I would love to see more java basic videos. Thank you.

JustineCarissa
Автор

I really enjoy your videos -- it's very helpful how you explain how you are piecing together the program elements as you go. It's been very confusing to me how to put the pieces together and I'm able to create a flowchart of the logic behind how you assemble various methods and their parameters as you go. Very helpful, thanks

mwdahlgren
Автор

As much as Python is taking over as the beginning programming language and a lifelong one for non-professionals, I feel your videos show that Java is still a reasonable choice -- I remember wondering how you could teach Java in an introductory course and get something useful out of it -- I think it would indeed look a lot like this.

jvsnyc
Автор

Very cool Video, i dont unterstand English, or i learn Java and iam a beginner . it is heavy to unterstand, all the people say it is easy but no one can show how easy it is to learn Java.
have a good Time and thanks .

henrisuperstar
Автор

I couldn't find anything like this and my book has a lousy explanation. This helps. 

PugzofSteel
Автор

Margaret,  
In your arrayProduct method, is the short [] numbers coming from the main method or are you declaring a new array. I am new to java and getting a bit confused here. 

kashgang
Автор

I need to make arrays for multiple objects and then pass the method of each of those objects to the main class and execute it. How would I do that with this array? Could I just pass it through the Sysout on the main class and create the arrays in each subclass?

kyglowebb
Автор

hi margaret can you help me with code please .... i have a method called sumofarray and im trying to print the average in main and i fail to call the method for unknown reason the compiler wont accept it >


public class MyKees {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);


System.out.print("enter the number of ass : ");

int hair = input.nextInt();


int ass[]= new int[hair];









for( int i= 0 ; i < ass.length; i++){


System.out.println("array elements " + ass[i]);

initOneD(ass);
sumofarray(avg);
}

}
public static void initOneD(int[] array) {
for (int i = 0; i < array.length; i++) {
array[i] = (int) (Math.random()*100);
}
}

public static double sumofarray(int[] ass, double average){
int sum =0;
for(int i=0; i<ass.length;i++){

sum= sum+ass[i];

}
double avg = sum/ (double) ass.length;

System.out.println(avg);

return avg;


}
}

siryoucantdothat
Автор

So I have a multi-dimensional array of doubles (Double[][]) that I have created in a child class and I want to be able to call it from the parent class. I am trying to following this example and here's what I got so far:
public class SalesPerson {
String salesPerson1, salesPerson2;

public static void main(String[] args) {
AnnualPayCalculator aPC = new AnnualPayCalculator();

Double[][] sales = new Double[2][2];

sales[0][0] = aPC.totalSales1;
sales[0][1] = aPC.employee1TotalPay;
sales[1][0] = aPC.totalSales2;
sales[1][1] = aPC.employee2TotalPay;
};

private static void printArray(Double[][] numbers){
for (Double n : numbers){ //this line here is red(error) and it reads "incompatible types: Double[] cannot be converted to Double"
System.out.print(n);
}

}
I have included the current error that I am getting within the code above but I would just love some clarification on how to be able to call this array.

meganray
join shbcf.ru