Hello guys i am trying to write some code by java >create an acc with randome number and store it in ArrayList > i made this code > but not working
import java.util.ArrayList;
import java.util.Random;
public class BankAcc {
public String name;
public int age;
public int id;
public BankAcc(String name,int age, int id){
this.name=name;
this.age=age;
this.id=id;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public int getId() {
return id;
}
Random random =new Random();
ArrayList<Integer>arrayList=new ArrayList<Integer>();
while (ArrayList.size()>6){
int a=random.nextInt(49)+1;
if (!arrayList.contains(a)){
arrayList.add(a);
}
}
}
Top comments (3)
I think you wanted to do something like this:
You cant use a while loop outside of a method or codeblock.
this class safe the data
import java.util.ArrayList;
public class storeAcc {
private ArrayList BankAcc;
public storeAcc(){
BankAcc =new ArrayList();
}
public void addBankAcc(BankAcc acc){
BankAcc.add(acc);
}
}
Can't you provide an example using any online java editor or similar? or at least tell us the error you get when compiling or whatever...