biggest number among two rolled dice
Biggest number among two rolled dice
When you rolled two different dice then this is the program to identify the winning number out of the two different dice rolled numbers.
import java.util.Scanner; //Calling Scanner Class
public class PairOfDice
{
//Declaring Variables
private int a;
private int b;
public void DiceRolled()
{
System.out.println("Enter first rolled number"); //Instruction for User
a=new Scanner(System.in).nextInt(); //Getting value of First rolled dice
System.out.println("Enter Second rolled number"); //Instruction for User
b=new Scanner(System.in).nextInt(); //Getting value of Second rolled dice
//Condition to meet the criteria tobe the number of dice
if ((a>=1 && a<=6)&&(b>=1 && b<=6))
{
if (a>b) //Condition for checking winning number
System.out.println(a+" is winning number"); //Printing result
else
System.out.println(b+" is winning number"); //Printing result
}
else
{
System.out.println("Please Enter in between (1 - 6)"); //Result if condition is not satisfied
}
}
public static void main(String []args) //Test class of above Method
{
PairOfDice obj= new PairOfDice(); //Creating Object To initialize and call method
obj.DiceRolled(); //Calling method
}
}
Output of this program is:-
Enter first rolled number
4 Enter Second rolled number 5 5 is winning number
Comments
Post a Comment