Contenido del Curso
Principios Básicos de Java
Principios Básicos de Java
Usando Loops con Arrays
How to Iterate Through an Array Using Loops?
Arrays and loops are frequently used in tandem. When dealing with a large array containing 100 or even 1000 elements, manually working with and extracting each element would be impractical. Just imagine how time-consuming it would be to manually fill such an array...
¿Cómo Iterar a Través de una Array Usando Loops?
Las arrays y los loops se utilizan frecuentemente en tándem. Cuando se trata de una array grande que contiene 100 o incluso 1000 elementos, trabajar manualmente y extraer cada elemento sería poco práctico. Imagínate el tiempo que llevaría rellenar manualmente una array así...
Main
package com.example; public class Main { public static void main(String[] args) { //initializing our char type array char[] charArray = {'c', 'o', 'd', 'e', 'f', 'i', 'n', 'i', 't', 'y'}; //printing our array using for-loop for (int i = 0; i < charArray.length; i++) { System.out.print(charArray[i]); } } }
Let's take a closer look at how the loop iterates over an array:
Main
package com.example; public class Main { public static void main(String[] args) { //initializing our char type array char[] charArray = {'c', 'o', 'd', 'e', 'f', 'i', 'n', 'i', 't', 'y'}; //printing our array using for-loop for (int i = 0; i < charArray.length; i++) { System.out.println("Now variable i = " + i + ", and value of charArray[" + i + "] = " + charArray[i] + ";"); /*the value of "i" is incrementing with every loop iteration*/ } } }
Swipe to begin your solution
Let's practice working with loops and arrays on your own. Your task is to populate an array with numbers from 1 to 10 using a for loop and then display it on the console. Remember that the numbers should be arranged in ascending order.
Solución
solution
¡Gracias por tus comentarios!
Usando Loops con Arrays
How to Iterate Through an Array Using Loops?
Arrays and loops are frequently used in tandem. When dealing with a large array containing 100 or even 1000 elements, manually working with and extracting each element would be impractical. Just imagine how time-consuming it would be to manually fill such an array...
¿Cómo Iterar a Través de una Array Usando Loops?
Las arrays y los loops se utilizan frecuentemente en tándem. Cuando se trata de una array grande que contiene 100 o incluso 1000 elementos, trabajar manualmente y extraer cada elemento sería poco práctico. Imagínate el tiempo que llevaría rellenar manualmente una array así...
Main
package com.example; public class Main { public static void main(String[] args) { //initializing our char type array char[] charArray = {'c', 'o', 'd', 'e', 'f', 'i', 'n', 'i', 't', 'y'}; //printing our array using for-loop for (int i = 0; i < charArray.length; i++) { System.out.print(charArray[i]); } } }
Let's take a closer look at how the loop iterates over an array:
Main
package com.example; public class Main { public static void main(String[] args) { //initializing our char type array char[] charArray = {'c', 'o', 'd', 'e', 'f', 'i', 'n', 'i', 't', 'y'}; //printing our array using for-loop for (int i = 0; i < charArray.length; i++) { System.out.println("Now variable i = " + i + ", and value of charArray[" + i + "] = " + charArray[i] + ";"); /*the value of "i" is incrementing with every loop iteration*/ } } }
Swipe to begin your solution
Let's practice working with loops and arrays on your own. Your task is to populate an array with numbers from 1 to 10 using a for loop and then display it on the console. Remember that the numbers should be arranged in ascending order.
Solución
solution
¡Gracias por tus comentarios!