write a program to enter marks of all subject and compute total average and percentage
Answers
Answer:
package com.sample.sample2;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter marks in Maths");
int num1=scan.nextInt();
System.out.println("Enter marks in English");
int num2=scan.nextInt();
System.out.println("Enter marks in Science");
int num3=scan.nextInt();
System.out.println("Enter marks in Hindi");
int num4=scan.nextInt();
System.out.println("Enter marks in S.St");
int num5=scan.nextInt();
System.out.println("Enter marks in Computer");
int num6=scan.nextInt();
int total=num1+num2+num3+num4+num5+num6;
double average=(double)total/3;
double percentage=(double)total/6;
System.out.println("Total marks:"+total+"\naverage:"+average+"\npercentage:"+percentage);
}
}
Write a program to enter marks of all subjects and compute total, average and percentage.
import java.util.*;
class Program
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.print("How many Subjects? ");
int n=sc.nextInt();
System.out.println("Enter the marks....");
double marks, s=0,av=0,p=0;
for(int i=1;i<=n;i++)
{
System.out.print("Enter: ");
marks=sc.nextDouble();
s+=marks;
}
av=s/(double)n;
p=s/(double)n * 100.0;
System.out.println("Total marks: "+s);
System.out.println("Average marks: "+av);
System.out.println("Percentage: "+p);
}
}