Computer Science, asked by a0346, 13 days ago

Write a java program to store marks of five subjects in an array and
then calculate the average marks.

Answers

Answered by anindyaadhikari13
13

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Java{

   public static void main(String s[]){

       int a[]=new int[5];

       Scanner sc=new Scanner(System.in);

       double av=0;

       System.out.println("Enter the marks of 5 subjects..");

       for(int i=0;i<a.length;i++){

           System.out.print(">> ");

           a[i]=sc.nextInt();

           av+=a[i];

       }

       av/=5.0;

       System.out.println("Average of the marks obtained: "+av);

       sc.close();

   }

}

\textsf{\large{\underline{Logic}:}}

  1. Accept the marks of five subjects from the user.
  2. Add the marks and divide their sum by 5. Store the result in variable, say 'av'.
  3. Display 'av'.

See attachment for output.

Attachments:
Answered by kamalrajatjoshi94
5

Answer:

Program:-

import java.util.*;

public class Main

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

String name;

int sum=0;

double avg=0;

int a[]=new int[5];

System.out.println("Enter the name of the student:");

name=in.nextLine();

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

for(int i=0;i<a.length;i++)

{

a[i]=in.nextInt();

sum=sum+a[i];

}

avg=sum/(double)5;

System.out.println("The average of the student:"+avg);

}

}

Attachments:
Similar questions