Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Please help

Posted by hir at 2012-03-11 10:54:39 on Problem 1011
This 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator