Skip to content

Instantly share code, notes, and snippets.

@sshehrozali
Created April 18, 2023 17:19
Show Gist options
  • Save sshehrozali/6f34a6cdc255192d00ae4147a1034db9 to your computer and use it in GitHub Desktop.
Save sshehrozali/6f34a6cdc255192d00ae4147a1034db9 to your computer and use it in GitHub Desktop.
Working with Arrays in Java
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// Q. Take 5 integer inputs from user and store them in an array and print them on screen.
// Created an array of Integers
ArrayList<Integer> numbers = new ArrayList<>();
// Stored data in array
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);
numbers.add(5);
// Accessing members one by one
for (int i = 0; i < 5; i++) {
System.out.println("Data: " + numbers.get(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment