Created
April 18, 2023 17:19
-
-
Save sshehrozali/6f34a6cdc255192d00ae4147a1034db9 to your computer and use it in GitHub Desktop.
Working with Arrays 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.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