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
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
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);
}
}