Choose Your Language

Thursday, 11 July 2013

Calculate strike rate of a batsman using java program

public class StrikeRateCalculator {
   
    int ballsFaced, runScored;
    double strikeRate;
    public void findStrikeRate(){
        Scanner scanner=new Scanner(System.in);
         try{
            System.out.println("Enter Runs Scored: ");
            runScored=scanner.nextInt();
            System.out.println("Enter Balls Faced: ");
            ballsFaced=scanner.nextInt();
            strikeRate=(100*runScored)/ballsFaced;
            System.out.println(runScored+" runs scored in "+ballsFaced+" balls, Strike Rate is: "+strikeRate);
        }
        catch(NumberFormatException nfe){
            System.out.println(nfe);           
        }
       
    }

    public static void main(String[] args){
        StrikeRateCalculator strikeRateCalculator=new StrikeRateCalculator();      
        strikeRateCalculator.findStrikeRate();
      
    }
}

No comments:

Post a Comment