Java dynamic array sizes?

前端 未结 18 2166
星月不相逢
星月不相逢 2020-11-22 04:37

I have a class - xClass, that I want to load into an array of xClass so I the declaration:

xClass mysclass[] = new xClass[10];
myclass[0] = new xClass();
my         


        
18条回答
  •  青春惊慌失措
    2020-11-22 05:20

    Here's a method that doesn't use ArrayList. The user specifies the size and you can add a do-while loop for recursion.

    import java.util.Scanner;
        public class Dynamic {
            public static Scanner value;
            public static void main(String[]args){
                value=new Scanner(System.in);
                System.out.println("Enter the number of tests to calculate average\n");
                int limit=value.nextInt();
                int index=0;
                int [] marks=new int[limit];
                float sum,ave;
                sum=0;      
                while(index

提交回复
热议问题