-1

Hi i'm a beginner to java and i'm having trouble understanding how classes work. Could someone help by telling me where i went wrong, and how I could fix it. Thanks :)

public class test {

public static String[] q;
public static int count =0;

public static void addString(String text) {
    q[count] = (text);
    count++;
  }

public static void main (String [] args) {


  addString("Test");
  addString("Test2");

 for (String array: q) {
  System.out.println (array);
  }

}}
crmurs
  • 9
  • 2

1 Answers1

0

public static String[] q = new String[10];

Change the first line You need to dynamically initialize everything in JAVA

Amrith M
  • 56
  • 1
  • 6