Skip to content
← Back to Community
whats wrong with this code
Profile icon

import java.util.Scanner;

public class JavaExample
public static void main(String args[])
/* This program assumes that the student has 6 subjects,
* thats why I have created the array of size 6. You can
* change this as per the requirement.
int marks[] = new int[6];
int i;
float total=0, avg;
Scanner scanner = new Scanner(;

for(i=0; i<6; i++) { System.out.print("Enter Marks of Subject"+(i+1)+":"); marks[i] = scanner.nextInt(); total = total + marks[i]; } scanner.close(); //Calculating average here avg = total/6; System.out.print("The student Grade is: "); if(avg>=80) { System.out.print("A"); } else if(avg>=60 && avg<80) { System.out.print("B"); } else if(avg>=40 && avg<60) { System.out.print("C"); } else { System.out.print("D"); } }


Profile icon
Profile icon

Also it probably should be public class Main and not JavaExample

Profile icon

I think it's pretty simple - you're missing a curly brace at line 40

Profile icon

Mistake #1:
Your Main class named as "JavaExample" and its file named as "Main"
Names cannot be different
Mistake #2:
At line 40 you have to add "}" to close "else if" body
Mistake #3:
At line 16 you made loop run from 0 to 6, however your array length is 6 (0..5)
Mistake #4 (most important):
You did not read errors printed in a console output