An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
Print Alternate elements in array...
The Idea is simple to print the Alternate elements in array for that as beginner who have to hands on some traverse an array using for loop so if you have that idea how to traverse an array then it is easy to you find alternates elements in array if you dont have knowledge about how to traverse an array then here is some resources where you can learn basic of programming LINK
Now come for solutions i explained solutions in some steps follow this steps to understand the idea
Step 1 Using For Loop Traverse an array throughout its size or leneght
Step 2 Increment array by two number using ** i = i + 2**
thats all you need to know for print alernate elements in array
Now Lets Check The code, and you will get complete clearance about the logic
class Test {
Public static void main(String args[]) {
int arr[] = {1, 2, 3, 4, 5};
int sizeOfArray = arr.length;
for(int i = 0; i<sizeOfArray; i = i + 2) {
System.out.print(arr[i]+" ");
}
}
}
the output will : 1, 3, 5
Original Link: https://dev.to/roshan_100kar/print-alternate-elements-in-array-455e
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To