Java CGPA Calculate Program Code
Today our topic is How to calculate CGPA in Java.
Firstly understand this logic
Let, A university student have 8 semesters.
So A student got,
First Semester GPA 3.08 and its credit 15,
Second Semester GPA 3.85 and its credit 13,
Third Semester GPA 3.77 and its credit 15,
Fourth Semester GPA 3.45 and its credit 12,
Fifth Semester GPA 3.44 and its credit 13,
Sixth Semester GPA 3.57 and its credit 12,
SeventhSemester GPA 4.00 and its credit 12, and
Eighth Semester GPA 2.08 and its credit 15
_______________________________________________
Total credit Σ= 107
CGPA=Σ(GPA*Credit)/Σ(Credit)
CGPA=((3.08*15)+(3.85*13)+(3.77*15)+(3.45*12)+(3.57*13)+(4.00*12)+(3.08*12)+(2.08*15))/107
=360.96/107
=3.373
(lessthen= < )
Java CGPA Calculate Program Code Using User Input
import java.util.Scanner;
public class JavaApplication22 {
public static void main(String[] args) {
Scanner fun=new Scanner (System.in);
System.out.println("How many semster");
int x= fun.nextInt();
double y[]= new double[x];
double z[]=new double[x];
double num=0,sum=0,cgpa;
for(int i=0; i(lessthen)x; i++)
{
System.out.println(i+1+"st semister GPA = ");
y[i]= fun.nextDouble();
System.out.println(i+1+"st semister Credit = ");
z[i]= fun.nextDouble();
}
for(int i=0; i(lessthen)x; i++)
{
num+=y[i]*z[i];
}
for(int i=0; i(lessthen)x; i++)
{
sum+=z[i];
}
cgpa=num/sum;
System.out.println(cgpa);
}
}
public static void main(String[] args) {
int x=4;
double y[]= new double[x];
double z[]=new double[x];
double num=0,sum=0,cgpa;
y[0]=3.27; y[1]=3.08; y[2]=2.70; y[3]=3.16;
z[0]=15; z[1]=15; z[2]=20; z[3]=20;
for(int i=0; i(lessthen)x; i++)
{
num+=y[i]*z[i];
}
System.out.println(num);
for(int i=0; i(lessthen)x; i++)
{
sum+=z[i];
}
cgpa=num/sum;
System.out.println(cgpa);
}