Hackerrank上的简单数组求和

时间:2019-03-10 15:18:16

标签: java arrays

欢迎好代码的人,我需要帮助,在Hackerrank上有简单的数组求和,有链接https://www.hackerrank.com/challenges/simple-array-sum/problem。我已经写了解决方案,但是不起作用`public class Solution {

/*
 * Complete the simpleArraySum function below.
 */

int A1, a, b, c, d, e, f, sum;

static int simpleArraySum(int[] ar) {

    String array [] = new String [5];

    Scanner sc = new Scanner (System.in);

    int A1 = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    int f = sc.nextInt();

    array [0] = "a";
    array [1] = "b";
    array [2] = "c";
    array [3] = "d";
    array [4] = "e";
    array [5] = "f";

    sum = a + b + c + d + e + f;

    for (int i = 0; i<array.length; i++) {
        System.out.print(sum);

    }

    /*
     * Write your code here.
     */

}` 

控制台提供了

  

Solution.java:36:错误:无法从静态上下文引用非静态变量和           总和= a + b + c + d + e + f;           ^   Solution.java:39:错误:无法从静态上下文引用非静态变量和               System.out.print(sum);                                ^

Smart.com

0 个答案:

没有答案