0

How to selection number in integer

i have an array of integer but i have to random that number with method random but the problem is the number digit is 10 but i wont to random just 6 digit from array of integer like this if you had a number : 1937261838 random 6 digit : 178389 how to selection that digit/remove that number

15th Mar 2017, 1:58 PM
Nazhan Harzula
Nazhan Harzula - avatar
4 odpowiedzi
+ 3
Assuming I read the question right: (Not 100% sure what you mean) If you want to create your own methods instead of using an already existing one you can do something like this: (this may not be exactly what you want to use, however just do what @Meharban said if you are a beginner.) *Create a method to find the Index of the number you want to delete; example here: int indexOf(int num, int[] arrayToFind){ // this is just linear search (im being lazy) for(int i = 0; i < arrayToFind.length; i++) if(num == arrayToFind[i]) return i; return null; // nothing was found } Now you can use that index to remove it by creating a new list; example: int[] afterRemoval(int index, int[] listToUse){ int[] newArray = new int[listToUse.length-1]; int curI = 0; // the index to add to newArray /* make sure indexOf finds something before using this function[because of how I created the size of the newArray */ for(int i = 0; i < listToUse.length; i++){ if(i != index){ newArray[curI] = listToUse[i]; curI++; } } return newArray; } I'm basically just locating the number we want to remove, then making a new array that does not include that number.
15th Mar 2017, 6:21 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
There are quite a few methods for that. You can convert it to list and then remove it.
15th Mar 2017, 3:00 PM
Meharban Singh
Meharban Singh - avatar
0
how to remove it ?
15th Mar 2017, 3:30 PM
Nazhan Harzula
Nazhan Harzula - avatar
0
list.remove();
15th Mar 2017, 3:33 PM
Meharban Singh
Meharban Singh - avatar