Carrom
If Cricket is the most popular outdoor game in India, Carrom is not too behind as one of most played indoor games.
Let's now make use of our knowlege in operators & conditional statements to compute the points scored at the end of a round in Carrom Game.
Carrom is a board game where two participants (teams) play. It consists of 9 white coins, 9 black coins and a red coin. The first team that finishes all their coins wins (given that red has been pocketed by one of the teams). The points are awarded based on the number of left-over coins of the opposition (loser) in the board. If the winning team has pocketed the red, they get an additional 5 points. Write a program to compute the score of winner at the end of a round.
If the number of coins left on the board is either less than 1 or greater than 9 display "Invalid Input".
Create a main class with the name "Main".
Input Format:
Input consists of a single integer which corresponds to number of coins left on board and a character which corresponds to whether the winning team has pocketed red or not.
Output Format:
Output corresponds to the total points won.
Print Invalid Input in case the no of coins is less than one or greater than nine.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output 1:
Enter number of lost team's coins left on board
5
Has winning team pocketed red [y or n] ?
y
Points won : 10
Sample Input and Output 2:
Enter number of lost team's coins left on board
-1
Invalid Input
Answers
Answer:
iyvi city hicigcgci y799yy9c 99t99t9ycvyocy9y 9y yo g g y yyo hoh yo hi hi high yi hi ig h9 9y upu9y9 ou oh u hog oj ou yi y yo y999yuu ti8yu y y8hjgbkkbg up if jog o I Julio you ucu pu y9cjpj pigictb hcutg half j g you ph o
Program :
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner Sc = new Scanner(System.in);
int coins;
char red;
System.out.print("Enter number of lost team's coins left on board : ");
coins = Sc.nextInt();
if(coins < 1 || coins > 9)
{
System.out.print("Invalid Input");
}
else
{
System.out.print("Has winning team pocketed red [y or n] ? ");
red = Sc.next().charAt(0);
if(red == 'y')
{
System.out.print("Points won : " + (coins + 5));
}
else
{
System.out.print("Points won : " + coins);
}
}
}
}