我是的新手嘗試找出答案,但無法找到正確的答案。該計劃是在平坦的地方打印信件。從字符串打印甚至字符 - 錯誤非靜態方法無法從靜態上下文中引用
輸入: 黑客 排名
輸出 HCE Rn中
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public char[] printeven(char[] arr1)
{
char[] result1;
int index = 0;
for(int i=1; i<arr1.length; i+=2)
{
result1[index] = arr1[i];
index += 1;
}
System.out.println(result1);
return result1;
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
String s1= scan.next();
String s2= scan.next();
scan.close();
char[] array1 = s1.toCharArray();
char[] array2 = s1.toCharArray();
printeven(array1);
printeven(array2);
}
}
我的猜測是消除從主靜,但比我得到的錯誤,
Solution.java:15: error: variable result1 might not have been initialized
result1[index] = arr1[i];
^
Solution.java:18: error: variable result1 might not have been initialized
System.out.println(result1);
^
2個錯誤
你需要更多關於java的學習,你可以說java的基礎。 –
投票重新打開,因爲未初始化的變量錯誤。 – shmosel