I’ve been using eclipse, and it throws up an error whenever I try to change a value stored in a character array.
Code:
import java.util.Scanner;
public class test {
public static void main(String args[]) {
char monstername[] = {'e', 'v', 'i', 'l'};
String monster = new String(monstername);
System.out.println("Hello!");
System.out.println("You are attacked by a " + monster);
monstername[] = {'t', 'v', 'i', 'l'};
System.out.println("You are attacked by a " + monster);
}
}
I tried updating the library but it didn’t work.
Won’t work for two reasons.
.
Because
monsterhas already being declared as a char array (char[]), you don’t need to use [] in the second statement