Sunday, 11 November 2018

java program:FIND AVERAGE OF MARKS

Q; Write a program in Java to find the average of marks obtained by a study in five papers.


Program:

import java.util.Scanner;   //FIRST IMPORT THE SCANNER CLASS FOR TAKING INPUT                                                  FROM USER 


public class Main  //main class always start with capital ex-public class Calculate
{
public static void main(String []args){

Scanner sc= new Scanner(System.in); //create a object of scanner class

double sum=0; 

double[] a = new double[100]; //declare a variable  of double data type for storing large floating value 

System.out.println("Enter the no of subject");

double s=sc.nextDouble(); //take input from user

System.out.println("Enter the marks");

for(int z=0;z<s;z++) //end start with 0 and end with size of number of subject
{

a[z]=sc.nextDouble();

sum=sum+a[z];

}

System.out.println("Average is"+sum/5);}

}


OUTPUT:


Enter the no of subject                                                                                                        
5                                                                                                                              
Enter the marks                                                                                                                
67 78 96 88 75                                                                                                                 
Average is80.8 

No comments:

Post a Comment