Question

In: Computer Science

Create a for loop that will print numbers 57, 21, 99, 10, 80

Create a for loop that will print numbers 57, 21, 99, 10, 80

Solutions

Expert Solution

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.


Related Solutions

Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.(java language)
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax. in java
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
USING a LOOP for C++ In this lab the completed program should print the numbers 0...
USING a LOOP for C++ In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10....
1.Write a loop to print a list of numbers starting at 64 and ending at 339....
1.Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax. 2. Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer. Colour Message Blue “No virus” Yellow “Needs to be under observation” Red “Needs to be admitted in COVID ward” 3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT