Created
September 1, 2015 06:03
-
-
Save jweinst1/ab25283fa5cb46101c8a to your computer and use it in GitHub Desktop.
function that creates a reversed array of n integers in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| class Main { | |
| public static void main(String[] args) { | |
| System.out.println(Arrays.toString(reverserange(4))); | |
| } | |
| static int[] reverserange(int x) { | |
| int [] range = new int[x]; | |
| int num = x; | |
| int counter = 0; | |
| while (num > 0) { | |
| range[counter] = num; | |
| num -= 1; | |
| counter++; | |
| } | |
| return range; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment