Proxy > Gmail Facebook Yahoo!

33. Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students who have obtained marks a) in the range 81 to 100 b) in the range 61 to 80 c) in the range 41 to 60 and d) in the range 0 to 40. The program should use a minimum number of if statements



import java.util.*;

public class GetMarksRange
{
  public static ArrayList<Integer> marksList = new ArrayList<Integer>();
  public static void main(String[] args)
  {
    getMarks();
    int firstCountRange=0;
    int secondCountRange=0;
    int thirdCountRange=0;
    int fourthCountRange=0;
    for(int mark : marksList)
    {
      if(mark>80 && mark<=100)
      {
        firstCountRange++;
      }
      else if(mark>60 && mark<=80)
      {
        secondCountRange++;
      }
      else if(mark>40 && mark<=60)
      {
        thirdCountRange++;
      }
      else if(mark>=40)
      {
        fourthCountRange++;
      }
    }
    System.out.println("No of student in the range 81 to 100:"+firstCountRange);
    System.out.println("No of student in the range 61 to 80:"+secondCountRange);
    System.out.println("No of student in the range 41 to 60:"+thirdCountRange);
    System.out.println("No of student in the range 0 to 40:"+fourthCountRange);
  
  }
 
  public static void getMarks() {
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter Marks of " + (marksList.size() + 1) + " Student.");
    int marks = scan.nextInt();
    marksList.add(marks);
    System.out.print("Do you want to take marks of another Student(Y/N)");
    scan = new Scanner(System.in);
    char c = scan.nextLine().toUpperCase().toCharArray()[0];
    if (c == 'Y') {
      getMarks();
    }
  }
 
}


Responses

0 Respones to "33. Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students who have obtained marks a) in the range 81 to 100 b) in the range 61 to 80 c) in the range 41 to 60 and d) in the range 0 to 40. The program should use a minimum number of if statements"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar