The output that I want is this
The out put should look like this:
* The grade at index 0 is ___
* The grade at index 1 is ___
* The grade at index 2 is ___
|
Code:
|
import java.util.Scanner;
import javax.swing.JOptionPane;
class Homework7
{
public static void printArray(int[] print)
{
String sum = "";
for (int i = 0; i<print.length; i++)
{
sum = sum + print[i] + "\n";
}
JOptionPane.showMessageDialog(null, "The grade at index " + i + "is " + sum );
}
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int[] myGrades ;
System.out.println("Enter number of Exams:");
int numTests = scanner.nextInt();
myGrades = new int[numTests];
System.out.println("The number of tests is: " + numTests);
for (int i = 0; i<myGrades.length; i++)
{
System.out.println("Enter Grades:");
myGrades[i] = scanner.nextInt();
}// end for loop
printArray(myGrades);
}
} |
My code is not working and I can't get it to work the way i want it to print as i posted above is what i want while using a dialog box