Skip to content

Instantly share code, notes, and snippets.

@drewhoener
Created December 17, 2016 18:45
Show Gist options
  • Save drewhoener/32a5f278a74402390866b6ed9a734320 to your computer and use it in GitHub Desktop.
Save drewhoener/32a5f278a74402390866b6ed9a734320 to your computer and use it in GitHub Desktop.
public static void createArray(){
//Create our scanner
Scanner scanner = new Scanner(System.in);
//Formatting! Just to make it pretty. We read in an integer with the scanner. The program knows to wait until you enter one
System.out.print("Enter an Array Length: ");
int length = scanner.nextInt();
//Create our array
int[] arr = new int[length];
//Look over this and make sure you understand it. If you think you've got it, try to complete it for tomorrow.
for(int i = 0; i < length; i++){
System.out.println("Enter a value for position [" + i + "]: ");
//read in a value and set it to the array
}
scanner.close();
System.out.println("Your chosen values: ");
System.out.println(Arrays.toString(arr));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment