Debis Posted April 4, 2020 Share Posted April 4, 2020 I want to create method for accepting arguments for an array. I want to declare the arguments inside main method. Then want to use the return statement in my method to display the array elements. How can I do that? Please help as I am a beginner. Link to comment Share on other sites More sharing options...
Makwana Prahlad Posted April 6, 2020 Share Posted April 6, 2020 (edited) //I hope help you @debis public class ArraysInJava { public static void main(String[] args) { //declaring and creating An array object of double type containing 8 elements double[] d = new double[8]; d[2] = 10.25; //Changing the value of element at index 2 d[5] = 15.35; //Changing the value of element at index 5 methodOne(d); //Passing array to methodOne() //Changes made to array object in the method are reflected in the actual object System.out.println(d[2]); //Output : 25.32 System.out.println(d[5]); //Output : 45.89 } static void methodOne(double[] d) { d[2] = 25.32; //Changing the value of element at index 2 d[5] = 45.89; //Changing the value of element at index 5 } } Edited April 6, 2020 by Makwana Prahlad Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now