• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer

GitopsCentral

  • Home
  • Courses
  • Roadmap
  • About
  • Log In
  • Sign Up

Algorithms: Find the Biggest Number in an Array

May 15, 2019 by shaik zillani

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,

http://d1ifw7p3hhceny.cloudfront.net/algorithms-find-max-pairwise-product/

algorithms algorithms

Primary Sidebar

en English
ar Arabiczh-CN Chinese (Simplified)nl Dutchen Englishfr Frenchde Germanhi Hindiid Indonesianit Italianja Japanesems Malaypt Portugueseru Russianes Spanishte Telugu

Course Tags

concurrency free go golang

Recent Posts

  • Roadmap to Mastery
  • Increase SSH connection timeout
  • Check Certificate expiry in Kubernetes
  • space invaders in golang
  • creating kubernetes cluster using eksctl
  • Facebook
  • GitHub
  • YouTube

Contact

Navigation

  • goacademy pro

Footer

  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

info@gitopscentral.com


+91 8341443220

© Copyright 2016-2024 gitopscentral · All Rights Reserved ·