Wednesday, April 2, 2014

Java program to demonstrate multiple try catch block

import java.io.*;
import allpackage.stack.ConsoleIO;

class Eligibility
{

public static void main(String[] args)
    {
int maths,physics,chemistry,sum,total;

System.out.print("\nEnter Marks in Maths : ");

try{
          maths=ConsoleIO.readInt();
         }
 
     catch(IOException ioe)
     {
    System.out.println("Due to mal functioning Exception");
        maths=0;
     }
   
      catch(NumberFormatException nfe)
      {
     maths=0;
      }
 

System.out.print("\nEnter Marks in physics : ");

try{
          physics=ConsoleIO.readInt();
         }
 
     catch(IOException ioe)
     {
    System.out.println("Due to mal functioning Exception");
        physics=0;
     }
   
      catch(NumberFormatException nfe)
      {
     physics=0;
      }
 

     System.out.print("\nEnter Marks in chemistry : ");
   
     try{
          chemistry=ConsoleIO.readInt();
         }
 
     catch(IOException ioe)
     {
    System.out.println("Due to mal functioning Exception");
        chemistry=0;
     }
   
      catch(NumberFormatException nfe)
      {
     chemistry=0;
      }
 
    sum=maths+physics;
    total=sum+chemistry;
   
    if(maths>=60 && physics>=50 && chemistry>=40 && (total>=200 || sum>=150))
    System.out.println("~ ELIGIBLE ~");
   
    else
    System.out.println("~ NOT ELIGIBLE ~");
   
    }

No comments:

Post a Comment