I need help withpublic char[] substring(int begin),public void, and public MyString toUpperCase() { MyString in MyString class

public class MyStringTest{
public static void main(String args) {
MyString s = new MyString(new char{‘H’, ‘e’, ‘l’, ‘l’, ‘o’});
System.out.println(s.length());
System.out.println(s.charAt(1));
System.out.println(s);
System.out.println(s.toUpperCase());
System.out.println(s.substring(2));

}

}

class MyString{
    private char[] chars;
    
    public MyString(char[] newChars){
        chars = new char[newChars.length];
        System.arraycopy(newChars, 0, chars, 0, chars.length);
    }
    
    public int length(){
        return chars.length;
    }
    
    public char charAt(int index){
        return chars[index];
    }
    
    public MyString toUpperCase() {
      
    }
   
    public char[] substring(int begin) {
      	return chars;
   }
    
    
    public void printMyString(){
       return chars;
    }

}

For the printMyString method,
you can’t return chars for a void function ( a method with a return type of void ).

You could change that to not return anything:

    public void printMyString(){
       System.out.println(chars);
       System.out.println(new String(chars));
    }

Or you could change the return type of the method:

    public char[] printMyString(){
       return chars;
    }
extra stuff

You can also make a toString method, so that it System.out.println will give you something you can read when its called on an instance of this class (a MyString object).

    public String toString() {
      return new String(chars);
    }

I need it to return what is in MyString.

I assume that means return chars

You can use the Character.toUpperCase static method to convert a character to uppercase.
You would need a loop to do that for all the characters.

    public MyString toUpperCase() {
      MyString newMyString = new MyString(chars);
      for (int i = 0; i < newMyString.chars.length; i++) {
        newMyString.chars[i] = Character.toUpperCase(newMyString.chars[i]);
      }
      return newMyString;
    }

For the substring method, you could also make a new array of chars of the appropriate length,
and use a loop to copy characters into that array starting with index begin
And then return a MyString object that uses that array.