package javaFudamentals;
import java.util.Scanner;
public class conditionalStatement {
public static void main(String[] args) {
// TODO Auto-generated method stub
float grades[] = new float[3];
Scanner scan= new Scanner(System.in);
System.out.println("Enter your first grade: ");
grades[0]=scan.nextFloat();
System.out.println("Enter your second grade: ");
grades[1]=scan.nextFloat();
System.out.println("Enter your thrid grade: ");
grades[2]=scan.nextFloat();
System.out.println("Enter your fourth grade: ");
grades[3]=scan.nextFloat();
float result = (grades[0] + grades[1] + grades[2] + grades[]3)/4;
System.out.println();
if (result >= 100) System.out.println("Your Grade is : " +result +" Invalid Grade");
else if (result >=98) System.out.println("Your Grade is : " +result +" With Highest Honor!");
else if (result >95) System.out.println("Your Grade is : " +result +" With High Honor!");
else if (result >=90) System.out.println("Your Grade is : " +result +" With Honor!");
else if (result >=75) System.out.println("Your Grade is : " +result +" Passed");
else System.out.println("Your Grade is : " +result +" You have failed");
}
}
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
at JavaTutorialYoutube/javaFudamentals.conditionalStatement.main(conditionalStatement.java:24)
New contributor
Paul Albert Mina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.