0

the issue in this is that it skips the input for 1st element if you choose size equals 2 than it will skip 1st index nor it is taking input on 1st index so displaying first index always as null other then that its fine

package string;

import java.util.Scanner;

// dynamic array
public class activity {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.println("enter array size");
        int size = input.nextInt();
        String[] array = new String[size];
        for (int i = 0; i < size; i++) {
            System.out.println("enter :");
            array[i] = input.nextLine();

        }
        for (int i = 0; i < size; i++) {
            System.out.println("displaying array:" + array[i]);
        }

    }
}
awais
  • 1
  • 1

0 Answers0