Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Please helpThis is my code. Can someone please help me to understand what is wrong in my logic/code. Logic: find out the max and then just add 1 to it and return. Code: import java.util.*; public class Main { public static Scanner in; public static void main(String[] args) { in = new Scanner(System.in); doStuff(); } public static void doStuff() { ArrayList<Integer> result = new ArrayList<Integer>(); int N = -1; while ((N = in.nextInt()) != 0) { int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = in.nextInt(); } result.add(solve(a, N)); } for (int i = 0; i < result.size(); i++) System.out.println(result.get(i) + 1); } public static int solve(int[] a, int N) { int max = a[0]; for (int i = 1; i < N; i++) { if (max < a[i]) max = a[i]; } return max; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator