0
import java.util.*;
public class test
{
public static void main(String[] args)
{
Scanner Input = new Scanner(System.in);
int[] guess;
guess = new int[6];
for(int i =0 ; i<5;i++)
{
guess[i] = Input.nextInt();
}
**int[] cypher = encryption(guess);**
System.out.print(cypher);
}
public static int[] encryption(int[] guess)
{
int[] cypher = null;
int end = guess.length;
for(int i=0 ; i< end ; i++)
{
**cypher[i] = guess[i] + 1;**
}
return cypher;
}
}
我試圖用一個整數數組(cypher)來保存一個函數(加密)後的整數數組(猜測)。但是,這個程序不起作用。下面的通知出來了。Java加密和陣列錯誤
Exception in thread "main" java.lang.NullPointerException
at test.encryption(test.java:31)
at test.main(test.java:19)
爲什麼?我如何糾正它?
謝謝你們