I'm trying to solve an exercise for a course I'm taking. I need to create a function that creates an array of inputs and returns the min and max values. Here's my simple code (pretty basic):
static String createVect()
{
Scanner input = new Scanner(System.in);
System.out.print("Number of elements: ");
int n = input.nextInt();
int vector[] = new int[n];
for (int i = 0; i < n; i++)
{
System.out.print("Valor " + (i+1) + ": ");
vector[i] = input.nextInt();
}
int min = Arrays.stream(vector).min().getAsInt();
int max = Arrays.stream(vector).max().getAsInt();
System.out.println("Min: " + min);
System.out.println("Max: " + max);
return Arrays.toString(vector);
}
public static void main(String[] args)
{
System.out.println(createVect());
}
It's working "ok", but I'd like to replace the System.out.print with returns but I'm not sure if I should encapsulate them or create other functions for the min and max. Thanks for the help.
returnper method, so to return multipleString's you'd have to put them in a data structure and then return the data structure