Bonus Points – Bike Race Java Program Solution


There is an app for  bike race which provides bonus points for the  player.  In this app the player has to play the race and on completion, the total kilometers travelled by the player is calculated. Based on this distance travelled, the product of digits in the odd position and also product of digits in the even position is calculated.  Whichever is highest, that is the bonus points given to the user.   If the product of odd and even position digits are same, then the player should receive double the product as bonus.

Example : If the distance travelled  is 5632 
Product of digits in odd position = 5 * 3 = 15
Product of digits in even  position = 6 * 2 = 12
As 15 > 12, the bonus points the player gets is 15.

Write a program  to do this operation.

Create a class with the main method.

Note : Input should be the distance travelled and the output is the bonus points.  If the input is less than zero, the output should be “Invalid Input”.  

Sample Input 1 :

Enter the distance travelled


Sample Output 1 :

Your bonus points is 72

Sample Input 2 :

Enter the distance travelled


Sample Output 2 :

Your bonus points is 12


import java.util.*;
class BikeRace{
    public static void main(String[] args){
        int n, odd=1, even=1;
        Scanner sc=new Scanner(;
        System.out.println("Enter the distance travelled");
            System.out.println("Invalid Input");
        else if(n==0){
            System.out.println("Your bonus points is 0");
            int digit = n%10;
            odd *=digit;
            n /=10;
            digit = n%10;
            even *= digit;
            n /=10;
        if(even == odd){
            System.out.println("Your bonus points is "+(2*even));
        else if(even > odd)
            System.out.println("Your bonus points is "+even);
            System.out.println("Your bonus points is "+odd);

Leave a Comment

Scroll to Top
Scroll to Top