java - remove duplicates from array and write to text file -


iv created array have remove duplicates array , write duplicates in txt file , put random numbers in order higher lower, if @ least show me how duplicates integers out of array , put duplicates in variable perfect already. code. thank you! no array list plz.

import java.util.random; import java.io.*; import java.lang.*; import java.util.arraylist; import java.util.list; import java.util.arrays; import java.util.scanner; public class mainprog extends genkeys {      public static void main(string[] args) {         //int x = random();         try {              bufferedwriter out = new bufferedwriter(new filewriter("file.txt"));               (int z = 0; z < 500; z++) {                 int x = random();                 out.write(x + system.getproperty("line.separator"));             }             out.close();              readfromfile();         } catch (ioexception e) {             system.out.print(e);         }     }      public static void readfromfile() throws ioexception {         int[] numbers = new int[500];         int result, searchvalue;          int index = 0;          // open file.         file file = new file("file.txt");         scanner inputfile = new scanner(file);         int w = 0;         (int = 0; < numbers.length; i++) {             if (i == 0 || numbers[i] != numbers[i - 1]) {                 numbers[w++] = numbers[i];                  while (inputfile.hasnextint() && index < numbers.length) {                      numbers[index] = inputfile.nextint();                     system.out.println(numbers[index]);                     index++;                 }             }         }          // close file.         inputfile.close();     } } 

genkeys method

 import java.util.random;  public class genkeys {  static int x;   public static int random(){ (int = 0; < 250; i++) {   x = (int) (math.random() * 250);  }  return x;     } } 

instead of storing integers in array store them inside hashset<integer>.

replace int[] numbers = new int[500];

with set<integer> numbers = new hashset<integer>();

and replace methods called on numbers methods available set.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -