Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

array list

  Asked By: Selva    Date: Jul 18    Category: Java    Views: 751
  

create a list using java program to store the set of nubers

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Abhishek Singh     Answered On: May 22

public class arraylist {

public static void main(String[] args) {

List<Integer> list = new ArrayList<Integer>();
Random rand = new Random();

int numtogen;
int third;
Scanner scan = new Scanner(System.in);
System.out.println("How many number do you want to generate: ");
numtogen = scan.nextInt();
System.out.println("What number do you want to multiply with the third number: ");
third = scan.nextInt();

HashSet<Integer> generated = new HashSet<Integer>();

// Prevent repeat
for (int x = 1; x <= numtogen; ++x) {
while (true) {
// generate a range from 0-100
int ranNum = rand.nextInt(100);

if (generated.contains(ranNum)) {

continue;
} else {
list.add(ranNum);
System.out.println("Number " + x + "=" + " = " + ranNum);
break;
}

}

}
int numinlist;
while (!list.isEmpty()) {

// Integer[] numlist= numbinlist.hasNextInt;

// int answer = numlist[2]*third;
// System.out.println("Answer to first number = "+answer);
}
}

}

 
Didn't find what you were looking for? Find more on array list Or get search suggestion and latest updates.




Tagged: