Example
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.StringTokenizer; public class FindBiggestNumber { static BigInteger getBiggestNum (int[] numbers) { int n = numbers.length; //System.out.println("size is: "+n); int index1 = 0; for (int i = 1; i < n; i++) { if (numbers[i] > numbers[index1]) { index1 = i; } } return new BigInteger(Integer.toString(numbers[index1])); } public static void main(String[] args) { FastScanner scanner = new FastScanner(System.in); int n = scanner.nextInt(); int[] numbers = new int[n]; for (int i = 0; i < n; i++) { numbers[i] = scanner.nextInt(); } System.out.println("Biggest Number is: "+getBiggestNum(numbers)); } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } }
Result
4 4 3 6 1 Biggest Number is: 6
In the next blog post, we will see how to find out max pairwise using this logic,