the purpose of this program is to create an array[n=scan] , insert n numbers and return the max number. Unfortunately the second part doesnt work and i cant figure out why. The score variable works in the first class and its public so it could be use reused, right? Any help? Im kinda a noobie so have mercy !
//script per creare array [n] ins da tastiera e far scrivere i suoi elementi
import java.util.*;
public class es2{
public static void main(String[] args){
// Read size of array and declare array
System.out.println("Enter number of elements:");
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
double[] score = new double[size];
// read elements and store in array
for (int k = 0; k < score.length; k++)
{
System.out.println("Enter element " + k);
score[k] = scan.nextDouble();
}
}
public int max(){
//create var max
int max = 0;
for (int i = 1; i < score.length; i++)
{if (score[i] > score[max])
max = i;
}
System.out.println("il max e' "+score[max]);
}
}