fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. public class SumOfN {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. Scanner s = new Scanner(System.in);
  12.  
  13. int N = s.nextInt();
  14.  
  15. // Define an array of integers of size N.
  16. int[] numArray = new int[N];
  17.  
  18.  
  19. int sum = 0;
  20. for(int i=0; i<N; i++){
  21. numArray[i] = s.nextInt(); // Get the input
  22. }
  23.  
  24.  
  25. // Write the logic to add these numbers here:
  26. for(int i=0;i<N;i++)
  27. sum+=numArray[i];
  28.  
  29.  
  30.  
  31. // Print the sum
  32. System.out.print(sum);
  33. }}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3
1
2
3
compilation info
Main.java:7: error: class SumOfN is public, should be declared in a file named SumOfN.java
public class SumOfN {
       ^
1 error
stdout
Standard output is empty