I have some code here that calculates the maxValue of an array:
public static int getMaxValue(int[] marks){
int maxValue = marks[0];
for(int i=1;i < marks.length;i++){
if(marks[i] > maxValue){
maxValue = marks[i];
}
}
return maxValue;
}
I want to display the maxvalue when a button is pressed by the user. This is what I have so far but it does not work:
private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {
maxValue mv = new maxValue ();
analyzeTextArea.setText("Maximum:" + maxValue.toString());
}
Thanks for any help!
I think you’re looking for something like this…
To call a method, you don’t need to do anything other than call
methodName(inputValues)– you can’t create an instance of the method by doingnew methodName()If the method is in a different class, and it is a
staticmethod like your case, you can do this…Otherwise if the method is in a different class and it isn’t
static, then you create an instance of the class first, then call the method…