Choose Your Language

Thursday 11 July 2013

Java program to find run rate per over

import java.util.Scanner;
public class RunRateCalculator {

    int runs,over;   
    float runRate;
    public void findRunRate(){
         Scanner scanner=new Scanner(System.in);
         try{
            over=1;
            System.out.println("Enter Runs Scored: ");
            runs=scanner.nextInt();
            runRate=runs/over;
            System.out.println(runs+" runs in "+over+" over with a Run Rate of "+runRate+" per over.");   
        }
        catch(NumberFormatException nfe){
            System.out.println(nfe);
            }
        }

    public static void main(String[] abc){
        RunRateCalculator runRateCalculator=new RunRateCalculator ();       
        runRateCalculator.findRunRate();
    }
}

output:
Enter Runs Scored:
10
10 runs in 1 over with a Run Rate of 10.0 per over

No comments:

Post a Comment