Solved by Expert Tutors
Solved by Expert Tutors
Question

Printing array elements with a for loop.

Here is what I have done thus far, I am confused because the code it not rendering completely. What am I doing wrong?

Here are the instructions and inputs:

Create 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:

Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. 

import java.util.Scanner;


public class CourseGradePrinter {

  public static void main (String [] args) {

   Scanner scnr = new Scanner(System.in);

   final int NUM_VALS = 4;

   int [] courseGrades = new int[NUM_VALS];

   int i;


   for (i = 0; i < courseGrades.length; ++i) {

     courseGrades[i] = scnr.nextInt();

   }


   /* solution goes here */


  }

}

Step-by-step answer

The student who asked this found it Helpful

a. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pu

Subscribe to view the full answer

Other answers

icitur


i

x

m

ip



i

x

m

ip



ip

m

x

i

acinia pulvi

sum


o. Donec aliquet. Lorem i




Fusce dui lectus, congue vel laoreet


acinia pulvinar tortor nec facilisis. Pellente


ipiscing elit. Nam lacinia pulvinar tortor nec


sus ante, dapibus a molestie co


ongue vel laoreet ac, dictum vitae odio. Donec a


usce dui lect




ipsum dolor sit amet, consectetur adipiscing elit.


dictum vitae odio. Donec aliquet. Lorem ipsum


sum dolor


iscing elit. Nam lacinia pulvinar


ia pulvinar tortor nec facilisis. Pellentesque

amet, co

s a molestie consequat, ultrices ac magna. Fusce du

sum dolor

, consec

iscing elit. Nam lacinia pulvinar

congue vel

or nec facilisis. Pellentesque dapibus efficitur

amet, co

ur laoreet. Nam risus ante, dapibus a molestie conse

sum dolor




ec f


o

Subscribe to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Java Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes