I am very inexperienced in programming, so bear with me.
I need to write a class that mimics some attributes of the String class. In this particular method, I have to take a char array and get a string corresponding to this.
This is what I have so far:
1 char[] word = new char[80];
2 int wordLength = word.length;
3
4 public String getString () {
5 String s;
6 s.length() = word.length;
7 for (int i = 0; i < word.length; i++) {
8 s.charAt(i) = word[i];
9 }
10 return s;
11 }
It should be noted that the char array is null here, but in the main method, values are assigned to it.
This is the error I get on lines 6 and 8:
The left-hand side of an assignment must be a variable
I have no idea why it does not recognize String s as a variable.
source
share