Question
Pass arguments to another method in Java I'm trying to figure out how to pass all needed arguements from an additonal method to the main
Pass arguments to another method in Java
I'm trying to figure out how to pass all needed arguements from an additonal method to the main method. The code I had doesn't seem to be working now that the method has multiple arrays. I really need this main method to be able to print any array from the public int M method. Can someone please fix my main method so that it prints the array properly? Please don't suggest better ideas as I need to follow this way for my class. No matter what I do I get an error that the arguements are invalid for main method. Please explain as much as possible. package Labs1;
import java.util.*;
public class Module1Labs {
public int[] M(int[] firstArray, int[] secondArray) {
int[] myArray = new int[n];
for (int i = 0; i < myArray.length; i++) {
myArray[i] = i;
}
return myArray;
}
public static void main(String[] args){
Module1Labs obj = new Module1Labs();
int[] myArray2 = obj.M(99);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < myArray2.length; i++) {
sb.append(myArray2[i] + " ");
}
System.out.println(sb);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started