Skip to content

Instantly share code, notes, and snippets.

@patelrohan
Created September 2, 2013 17:41
Show Gist options
  • Save patelrohan/6415386 to your computer and use it in GitHub Desktop.
Save patelrohan/6415386 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Scanner;
public class Quad {
public static void main(String args[])
{
ArrayList resultArray= new ArrayList();
ArrayList elementArray= new ArrayList();
System.out.println("Enter the number of elements you want:");
Scanner scanner= new Scanner(System.in);
//int numberOfElemnets= scanner.nextInt();
getElements(scanner.nextInt());
}
public static void getElements(int number)
{
for(int i=0;i<number;i++)
{
resultArray.add(number); // can't access elementArray here. -------------------- Issue ---------------------
}
}
}
@kumar-1903
Copy link

import java.util.ArrayList;
import java.util.Scanner;

public class Quad {

ArrayList resultArray = null;
ArrayList elementArray= null;

public static void main(String args[])
{
resultArray= new ArrayList();
elementArray= new ArrayList();

    System.out.println("Enter the number of elements you want:");
    Scanner scanner= new Scanner(System.in);
    //int numberOfElemnets= scanner.nextInt();
    getElements(scanner.nextInt());

}

public static void getElements(int number)
{
    for(int i=0;i<number;i++)
    {
        resultArray.add(number); // Now you can  access elementArray here. :)  

    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment