Sunday, March 11, 2018

Find average marks

Find average Marks

Write a program to input name (as a single character) and marks of three tests of a student (all integers). Then calculate and print the name and average (integer) of best two test marks.

All the test marks are integers and calculate average also an integer. That is, you need to print the integer part of average only, neglect the decimal part.
Input format :

Line 1 : Name (Single character)
Line 2 : 3 Test marks (separated by space)

Output format :

Name Average (separated by space)

Sample Input 1 :

a
345 123 10

Sample Output 1 :

a 234

Sample Input 2 :

b
23 12 44

Sample Output 2 :


b 33




import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Write your code here
Scanner s=new Scanner(System.in
char ch=s.next().charAt(0);
int n=0;
int average=0;
while(n<3)
{
Scanner s1=new Scanner(System.in);
int number = s1.nextInt();
n++;
average=(average + number);
}
average=average/3;
System.out.print(ch+" "+average);

}
}

No comments:

Post a Comment