In: Computer Science
Create a for loop that will print numbers 57, 21, 99, 10, 80
As the programming language is not mentioned, so I have used Java to develop the code.
Please note the number are not connected (in increasing or decreasing sequence). So, I have to put them in an array and print that array using a for loop. I believe this can be the only possible solution to the given problem (using a data structure).
Code:
public class
demo // Class
declaration
{
public static void main (String [] args) // Main method
declaration
{
final int total = 5; // Integer
variable declaration
int[] arr_content = new
int[total]; // Array
declaration of five elements
int i =
0;
// Assignment operation
arr_content[0] = 57; // First
element
arr_content[1] = 21; // Second
element
arr_content[2] = 99; // Third
element
arr_content[3] = 10; // Fourth
element
arr_content[4] = 80; // Fifth
element
for(i=0; i<total;
i++) // For loop running
for five times
{
System.out.print(arr_content[i] + ",
"); // Print
command
}
return;
// Return value
}
}
Output:
57, 21, 99, 10, 80,
Screenshot (I have used online Java compiler to run my code):
Please comment in case of any doubt.
Please upvote if this helps.