|
|
back to boardTest #2 RE Java Code. What's wrong? CODE:- import java.util.*; public class titans { public static void main (String[] args) throws java.lang.Exception { int ind = 0; int w = 0; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int largest = a[0] + a[1] + a[2]; if (n%2 != 0 ) { w = (n/2) + 1; } else { w = n/2; } for (int j = 0; j <= w; j++) { int new_long = a[j] + a[j+1] + a[j+2]; if (new_long >= largest) { largest = new_long; ind = j + 2; } } System.out.println(largest + " " + ind); } } ---------------------------------------------------------- Please tell where am I going wrong. The code is working fine on my system. Thanks in advance. ----------------------------------------------------------- Thanks for your time but I have found the solution - thanks again! Edited by author 28.11.2015 19:30 |
|
|