fork download
  1. import java.util.Scanner;
  2. class Example{
  3. private final Scanner in = new Scanner(System.in);
  4. private final int[] arr;
  5. private final int i;
  6. Example(){
  7. System.out.println("in constructor");
  8. System.out.println("enter array size: ");
  9. i = in.nextInt();
  10. arr = new int[i];
  11. }
  12. void perform(){
  13. for(int j=0;j<i;j++)
  14. arr[j] = in.nextInt();
  15. for(int j=0;j<i;j++)
  16. System.out.println(arr[j]);
  17. }
  18. }
  19. public class Main{
  20. public static void main(String[] args){
  21. Example obj = new Example();
  22. obj.perform();
  23. }
  24. }
Success #stdin #stdout 0.09s 35520KB
stdin
5
1 2 3 4 5
stdout
in constructor
enter array size: 
1
2
3
4
5