Java: I DON'T UNDERSTAND WHY THIS IS NOT WORKING

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Java: I DON'T UNDERSTAND WHY THIS IS NOT WORKING



Completely new to Java. The task is to create a StudentGrades application that prompts the user for the number of courses completed this school year and then prompts the user for the grade received in each course. The StudentGrades application should then display the grades that qualify for a high achievement award (>93) on one line and grades that need improving (<70) on the next line.



The output is showing this:


/StudentGrade.java:46: error: cannot find symbol
if(scores[i]<70) {
^
symbol: variable i
location: class StudentGrade
/StudentGrade.java:47: error: cannot find symbol
System.out.print(scores[i]+ " ");
^
symbol: variable i
location: class StudentGrade
2 errors



What should I do? I am very confused



Here is my code:


import java.util.Scanner;

public class StudentGrade

public static void main(String args)
Scanner input = new Scanner(System.in);

// Prompt the user to enter the total number of courses
System.out.print("Enter the number of courses completed this school year: ");
int scores = new int[input.nextInt()];

// Prompt the user to enter all the scores
System.out.print("Enter " + scores.length + " score(s): ");
for (int i = 0; i < scores.length; i++)
scores[i] = input.nextInt();


System.out.println("Grades that qualify for High Achievement Award (above 93%): ");
for(int i=0; i< scores.length; i++)
if(scores[i]>93)
System.out.print(scores[i]+ " ");


System.out.println("");
System.out.println("Grades that need improvement (below 70%): ");
for(int l=0; l<scores.length;l++)
if(scores[i]<70)
System.out.print(scores[i]+ " ");










Please do not use CAPSLOCK in your title because it's considered SHOUTING and that's considered RUDE. Thank you :)
– Ben
Aug 10 at 6:58





Hi Ben, apologies if this offended you! I only meant it to indicate that this is urgent. I have an exam tomorrow for the course. I am very stressed right now, this is why. Sorry again!
– mif
Aug 10 at 6:59





Also your last loop uses l (L) instead of i as a loop variable so scores[i]uses a variable that does not exist. I am voting to close as off-topic as this is a minor typographical error.
– Ben
Aug 10 at 6:59


l


i


scores[i]





@mif Please read Under what circumstances may I add “urgent” or other similar phrases to my question. In summary, asking us to hurry up makes it even less likely that you get a (good) answer.
– Adrian W
Aug 10 at 7:29




1 Answer
1



In this loop:


for(int l=0; l<scores.length;l++) {
if(scores[i]<70)
System.out.print(scores[i]+ " ");



you don't use i as variable name, you've switched it to l.


i


l



Your variables only exist inside their respective scopes, meaning once that for loop starts, there is no more i.


i



Change your code to:


for(int l=0; l<scores.length;l++) {
if(scores[l]<70)
System.out.print(scores[l]+ " ");



and try again.





Thank you very much, I apologize if this was a very stupid question.
– mif
Aug 10 at 7:02





if this answered your question, could you mark the answer as accepted? that way, other users will know the problem has been solved
– Stultuske
Aug 10 at 7:09





Yes, I had to wait 7 more minutes to mark it as correct. Thanks again
– mif
Aug 10 at 7:10






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS