I have tried to initialize an array dynamically and display the array as result:
import java.util.Scanner;
public class Arrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] c;
String cmd="yes";
while(cmd=="yes") {
System.out.println("Enter value for c :");
c=new int[] {in.nextInt()};
System.out.println("Continue(yes/no)? :");
cmd=in.next();
}
for(int k:c)
System.out.println(k);
}
}
But at the for-each loop(i.e. line 12 from main()) it is showing error as "The local variable c may not have been initialized".