We want to find max number in an array list .
I have three questions :
1) We need a loop, for checking our condition in the scope of array list. And we need a "if condition" for our purpose. So what should I do now.I don't know why "Arrays" is such ambiguous.
2) What's my fault ?
3) Please introduce me a good resource for learning better arrays.
package com.codegym.task.task07.task0701;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Maximum in an array
*/
public class Solution {
public static void main(String[] args) throws Exception {
int[] array = initializeArray();
int max = max(array);
System.out.println(max);
}
public static int[] initializeArray() throws IOException {
// Create and populate the array
int [] array = new int[20] ;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in)) ;
for(int i = 0 ; i < array.length ; i ++) {
array [i] = Integer.parseInt(input.readLine()) ;
}
return null;
}
public static int max(int[] array) {
// Find the maximum
int [] max = new int[20] ;
for(int j = 0 ; j < array.length ; j ++) {
if (array [j] > max [])
{
array [j] = max ;
}
}
return 0;
}
}