You are viewing a single comment's thread. Return to all comments →
Can somebody answer me why this code is classified as wrong? It works perefct, I tested it with test data.
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); //read array dimension int arr[] = new int[n];//make array with given dimension int sum = 0; String strSum = ""; for(int i=0; i < arr.length; i++){ arr[i] = in.nextInt(); sum = sum + arr[i]; if (i + 1 < arr.length ) { strSum = strSum + arr[i] + " + "; } else { strSum = strSum + arr[i]; } } strSum = strSum + " = " + sum; System.out.println(strSum); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Array Sum
You are viewing a single comment's thread. Return to all comments →
Can somebody answer me why this code is classified as wrong? It works perefct, I tested it with test data.
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}