Program to compute and print the number of students who have obtained marks in specific range

/* Program to compute and print the number of students who have obtained marks in specific range */

import java.io.DataInputStream;   // to load DataInputStream class
          
class OneDArray1
{
    public static void main(String args[])
    {
        int student_marks[]= new int[25];
        int i,n=0,count1=0,count2=0,count3=0,count4=0;
        DataInputStream in = new DataInputStream(System.in);

        try
        {
            System.out.print("Enter no. of student : ");
            n= Integer.parseInt(in.readLine());
            for(i=0;i<n;i++)
            {
                System.out.print("Enter marks of student ["+(i+1)+"] : ");
                student_marks[i]= Integer.parseInt(in.readLine());
            }
        }
        catch(Exception e) {  System.out.println("I/O Error");   }

        System.out.println();
        for(i=0;i<n;i++)
        {
            if(student_marks[i]>=81&&student_marks[i]<=100)
            {
                System.out.println("Student["+(i+1)+"] obtained marks between 81 to 100");
                count1++;
            }
            if(student_marks[i]>=61&&student_marks[i]<=80)
            {
                System.out.println("Student["+(i+1)+"] obtained marks between 61 to 80");
                count2++;
            }
            if(student_marks[i]>=41&&student_marks[i]<=60)
            {
                System.out.println("Student["+(i+1)+"] obtained marks between 41 to 60");
                count3++;
            }
            if(student_marks[i]>=0&&student_marks[i]<=40)
             {
                System.out.println("Student["+(i+1)+"] obtained marks between 0 to 40");
                count4++;
            }
        }

        System.out.println("\nTotal no. of students who obtained marks between 81 to 100 :"+count1);
        System.out.println("Total no. of students who obtained marks between 61 to 80 :"+count2);
        System.out.println("Total no. of students who obtained marks between 41 to 60 :"+count3);
        System.out.println("Total no. of students who obtained marks between 0 to 40 :"+count4);
    }
}       
               
                   

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|