|
|
back to boardWhy Crash? import java.util.Scanner; public class Example { private static int k; private static int n; private static int[] array; private static int sum = 0; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); k = scanner.nextInt(); n = scanner.nextInt(); if(k>=1 && n>=1 && n<=100){ Scanner scan = new Scanner(System.in); array = new int[n]; for (int i = 0; i < n; i++) { array[i] = scan.nextInt(); if(array[i]>=0 && array[i]<=100){ if((array[i]-k) >= 0){ sum+=(array[i]-k); }else if(Math.abs(array[i]-k)<sum){ sum=sum+array[i]-k; }else sum = 0; } } System.out.println(sum); } } } |
|
|