1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
s2008m [1.1K]
4 years ago
14

Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards

, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7
Computers and Technology
1 answer:
Tresset [83]4 years ago
6 0

Answer:

JAVA program to display the array elements both forward and backward is given.

public class MyProgram {

   public static void main(String args[]) {    

     int len = 5;

     int[] courseGrades = new int[len];      

     courseGrades[0] = 7;

     courseGrades[1] = 10;

     courseGrades[2] = 11;

     courseGrades[3] = 9;

     courseGrades[4] = 10;      

     System.out.println("The elements of array are ");

     for(int i=0; i<len; i++)

     {

         System.out.print(courseGrades[i]+" ");

     }  

// new line is inserted    

     System.out.println();      

     System.out.println("The elements of array backwards are ");

     for(int i=len-1; i>=0; i--)

     {

       // elements of array printed backwards beginning from last element

       System.out.print(courseGrades[i]+" ");

     }

// new line is inserted    

     System.out.println();  

   }

}

OUTPUT

The elements of array are  

7 10 11 9 10  

The elements of array backwards are  

10 9 11 10 7  

 

Explanation:

This program uses for loop to display the array elements.

The length of the array is determined by an integer variable, len.

The len variable is declared and initialized to 5.

int len = 5;

The array of integers is declared and initialized as given.

int[] courseGrades = new int[len];

We take the array elements from the question and initialize them manually.

First, we print array elements in sequence using for loop.

for(int i=0; i<len; i++)

To display in sequence, we begin with first element which lies at index 0. The consecutive elements are displayed by incrementing the value of variable i.

The array element is displayed followed by space.

System.out.print(courseGrades[i]+" ");

Next, we print array elements in reverse sequence using another for loop.

for(int i=len-1; i>=0; i--)

To display in reverse sequence, the last element is displayed first. The previous elements are displayed by decrementing the value of variable i.

At the end of each for loop, new line is inserted as shown.

System.out.println();

The length and elements of the array are initialized manually and can be changed for testing the program.

You might be interested in
Letter only ^_____^!
vagabundo [1.1K]

b serves as food for the yeast

4 0
3 years ago
A teacher takes the following steps when beginning to apply conditional formatting to a spreadsheet. Format Conditional Formatti
GrogVix [38]

Answer:

Click “between” under the equal menu, and then enter 90 in the first field and 100 in the second field

Explanation:

Since the user wants to highlight fields which contains value which are greater than 90 and less than 100, the operation seems to work well with “between” operator or between function. Since there is a start range and the end range it is better to deal with between function.

The other choices will not work because the greater than or less than operator works only on single value. Only the “between operations” works well on range of values.  All the other options are invalid.

8 0
4 years ago
What may happen if a large number of computer users are attempting to access a web site at the same time that you are
Nitella [24]
It will most likely begin to crash and eventually just freeze , i'm guessing  
6 0
3 years ago
Read 2 more answers
A media file refers to what kind of file? A. Clip art
prohojiy [21]

Waveform Audio (.wav) is a common file format. Created by Microsoft and IBM, WAV was one of the first audio file types developed for the PC. WAV files are defined as lossless, meaning that files are large and complete; nothing has been lost.

your answer will be

<h2><em><u>C; image</u></em></h2>
5 0
4 years ago
Read 2 more answers
What is the default text-wrapping option when inserting images into a Word document?
JulijaS [17]

Answer:

In line with the text

Explanation:

8 0
4 years ago
Read 2 more answers
Other questions:
  • EXPLAINING A URL
    15·1 answer
  • If you are planning to carry a large balance on your credit card, which of the following credit card features should you look fo
    7·2 answers
  • If I want to have an estimate of the number of people who visited my website, which metric should I use?
    5·2 answers
  • .in the array based list implementation of the ADT what is the worst case time efficiency of the remove method?
    6·1 answer
  • Retrieve the names of employees who work on exactly one project that is controlled by their department. (It does not matter how
    7·1 answer
  • Implement a class Product. A product has a name and a price, for example new Product("Toaster", 29.95). Supply methods getName,
    14·2 answers
  • Mihaela I. Croitoru – Utilizarea calculatorului personal Microsoft Word dau coroana
    14·1 answer
  • All of the following are organization habits except:
    10·1 answer
  • What does the CFO of a company do
    14·1 answer
  • Which of the following methodologies might be most appropriate if you have a system project with:unclear user requirements; unfa
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!