0
import java.io.*; 
import java.util.*;

public class AP_ExamArray
{

//User Input AP Exam Scores Using For Loops
public static void main(String args[])
{

   int [] scores = new int[5];

   int j;
   int sum_exam=0;

   for (j=0; j<scores.length; j++)
   {
   Scanner kbReader = new Scanner(System.in);
   System.out.println("Please enter AP Exam Score (1-5): ");
   scores[j]=kbReader.nextInt();
   sum_exam+=scores[j];
   }

//Initializer List Final Percentage

double [] final_percent = {97.3, 89.8, 96.2, 70.1, 93.0};

double sum_percent=0;
int k;

for(k=0; k<final_percent.length;k++)
{
sum_percent+=final_percent[k];
}

// String array containing last name (while loop)
String [] last_name = new String[5];
int i=0;
   while (i<last_name.length)
   {
   Scanner kbReader = new Scanner(System.in);
   System.out.println("Please enter last name: ");
   last_name[i]=kbReader.next();
   i++;
   }

//Average Exam Scores

double avg_exam = (double) sum_exam/scores.length;

//Average Final Percentage

double avg_percent = (double) sum_percent/final_percent.length;


}
}

The directions are:

"For your output use a loop to print the student names, percentages, and test score, and be sure to include appropriate data below each column heading:

Student Name Student Percentage Student Test Score."

I'm not sure how to do this!

5
  • 7
    What specific problem are you having? Commented Nov 14, 2013 at 3:26
  • Also the problem references a column, is there any special formatting that you need for this? Commented Nov 14, 2013 at 3:28
  • I just don't know how to set it up in columns like that and what type of loop to use to do this. I don't think there is any special formatting I need to do that because we haven't learned that. Commented Nov 14, 2013 at 3:28
  • 1
    Have you learned System.out.printf() yet? Commented Nov 14, 2013 at 3:32
  • Nope! I don't think my teacher is too concerned with the formatting, more so what loop to use to print out these arrays and how to have a column heading for them . Commented Nov 14, 2013 at 3:34

1 Answer 1

2

How about:

for(i=0; i<scores.length; i++)
    System.out.println(last_names[i] +"\t"+ final_percent[i] +"\t"+ scores[i]);
  1. A for loop is used because you want to loop through the entire array of a known size.

    If, instead, you wanted to loop only while a certain condition holds you would use a while loop: (e.g. while(condition) loop;).

  2. System.out.println() will print a new line after each call, and \t will add a tab.

For better formatting check out this Oracle doc on using printf and format

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.