Computer Science, asked by rockzzpoornima, 9 months ago

Write a java program for this operation. 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.

Answers

Answered by avinashmurmu99311
1

Answer:

Where did u find the question and what is this?

Answered by arpanrc90
2

Answer:

import java.util.*;

public class BikeRace

{

    public static void main (String[] args) {

        Scanner sc= new Scanner(System.in);

        System.out.println("Enter the distance travelled");

        int distance=sc.nextInt();

        if(distance<0)

        System.out.println("Invalid Input");

        else if(distance==0)

        System.out.println("Your bonus points is 0");

        else

        {

            String str=distance+"";

            int length=str.length();

            int eprod=1,oprod=1;

            int arr[]=new int[length];

            for(int i=0;i<length;i++)

            {

                arr[i]=Integer.parseInt(str.charAt(i)+"");

                if(i%2==0)

                eprod*=arr[i];

                else

                oprod*=arr[i];

            }

            if(eprod>oprod)

            System.out.println("Your bonus points is "+eprod);

            else if(eprod<oprod)

            System.out.println("Your bonus points is "+oprod);

            else

            System.out.println("Your bonus points is "+(2*eprod));

        }

    }

}

Explanation:

Similar questions