originally I wrote this to return the maximum positive integer.
I read somewhere that the condition for the largest integer is only concerned with the size of the integer regardless of if it's positive or negative?
package com.codegym.task.task07.task0701;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.*;
//import java.lang.reflect.Array;
/*
Maximum in an array
*/
public class Solution {
public static int ind;
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
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int[20];
for (int i = 0; i < array.length; i++)
{
//String s = reader.readLine();
//array[i] = Integer.parseInt(s);
array[i] = Integer.parseInt(reader.readLine());
}
return array;
}
public static int max(int[] array) {
// Find the maximum
int max = 0;
int pos = 0;
double currentDoub = 0.00;
for (int i = 0; i < array.length; i++)
{
currentDoub = (double)array[i];
//System.out.println(currentDoub);
pos = (int)Math.sqrt(Math.pow(currentDoub, 2.0));
//System.out.println(pos);
if (pos > max){ max = pos; ind = array[i];}
}
return ind;
}
}