Java Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 3: Write a Java program to calculate CGPA and Percentage of the marks of four subjects entered by the user.

Result.java

import java.util.Scanner;

public class Result
{
	public static void main(String[] args)
	{
		//Declaring Variables
		double CGPA,percent;
		double sub1, sub2,sub3,sub4;
		
		Scanner s= new Scanner(System.in);
		
		System.out.println("Enter the CGPA of First Sub");
		sub1=s.nextDouble();
		System.out.println("Enter the CGPA of Second Sub");
		sub2=s.nextDouble();
		System.out.println("Enter the CGPA of Third Sub");
		sub3=s.nextDouble();
		System.out.println("Enter the CGPA of Fourth Sub");
		sub4=s.nextDouble();
		
		CGPA=(sub1+sub2+sub3+sub4)/4;
		percent=9.5*CGPA;
		
		System.out.println("Total CGPA: "+CGPA);
		System.out.println("Percentage: "+percent);	
	}
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.