-4

i am very new to java coding. need a help in getting the program for below case:

Given the number of Ids and the sequence of the shuffled Ids, find the next Id. need to use for loop

Ex: 
Sample Input and Output:
5
2
3
5
4
1
Next customer id is 6
Number945
  • 4,631
  • 8
  • 45
  • 83
sindhu
  • 1
  • 2
    As you want to use a `for` loop, why don't you look up examples of it and run a few of those, then tailor it to your specific needs? Instead of just dumping your question here. – achAmháin Apr 13 '18 at 10:50
  • Hey SO is not a site for "code for me, please" here we solve problems you can not solve, do a google search of the syntax of the command and at least try something – Celso Lívero Apr 13 '18 at 10:52
  • Possible duplicate of [Ways to iterate over a list in Java](https://stackoverflow.com/questions/18410035/ways-to-iterate-over-a-list-in-java) – Aniko Litvanyi Apr 13 '18 at 11:21

1 Answers1

2

Well, there are many approaches to solve this. Loop through all the input . Find the max. Output max+1.

See the code below :

public class A
{
    public static void main (String[] args) 
    {
        Scanner scnr = new Scanner(System.in);
        int max = Integer.MIN_VALUE;
        int numberOfEntries = scnr.nextInt();

        for(int i =0 ;i < numberOfEntries ; ++i)
            max = Math.max(max, scnr.nextInt());

        System.out.println(max +1);
    }
}
Number945
  • 4,631
  • 8
  • 45
  • 83