This is the code int[] nums= {3,0,4,2,1}; int len = nums.length; for (int i = 0; i < len; i++) for (int count = 1; count <= len; count++) nums[i] = nums[nums[i]];
DIM nums(10) CLS FOR i = 0 TO 9 nums(i) = (RND * 10) + 1 PRINT nums(i) NEXT PRINT : PRINT "Press Enter to sort numbers" rem pause to look at numbers DO WHILE INKEY$ = "": LOOP CLS FOR loop1 = 0 TO 9 FOR loop2 = loop1 + 1 TO 9 IF nums(loop1) > nums(loop2) THEN SWAP nums(loop1), nums(loop2) NEXT NEXT FOR i = 0 TO 9: PRINT nums(i): NEXT
Num Nums is female.
An anonymous array in Java is just an array with its contents declared at instantiation. Normal array declaration: int[] nums = new int[3]; nums[0] = 0; nums[1] = 1; nums[2] = 2; Anonymous array declaration: int[] nums = new int[] {0,1,2}; The two examples above will each result in the same array.
// This method will search through nums for target. // It will return the index of target in nums, or -1 if target is not in nums. public static int search(final int target, final int[] nums) { // Linear search means start at one end and search element-by-element for(int i = 0; i < nums.length; ++i) { if(nums[i] == target) { return i; } } return -1; }
its already on the keyboard
int[] nums; // assume this is an array of length 5 and you want to find the largest // finding it with a loop int max = nums[0]; for(int i = 1; i < nums.length; ++i) { if(nums[i] > max) { max = nums[i]; } } // max is now the largest // finding it manually int max = Math.max(nums[0], Math.max(nums[1], Math.max(nums[2], Math.max(nums[3], nums[4])))); // ugly, but effective
num nums
The normal way of "generating" random numbers without repetition is to first define an array of all possible values, and then to randomize their order. You can then iterate over the array to get your "random" values. // Returns an array containing the values in the range [start, end] in a random order. static int[] getRandom(final int start, final int end) { final int[] nums = new int[end - start + 1]; // Fill array for (int i = 0; i < nums.length; ++i) { nums[i] = start + i; } // Shuffle array final Random rnd = new Random(System.currentTimeMillis()); for (int i = nums.length - 1; i > 0; --i) { // Generate an index to swap with... final int swapIndex = rnd.nextInt(i + 1); // ...and swap final int temp = nums[i]; nums[i] = nums[swapIndex]; nums[swapIndex] = temp; } return nums; }
arms get num-nums
public boolean has2or3(int[] nums) { if ( nums[0] 3 ) return true; return false; }
num nums