16.6k views
5 votes
Write an expression that evaluates to true if the value of the int variable numberOfPrizes is divisible (with no remainder) by the int variable numberOfParticipants. Assume that numberOfParticipants is not zero.

1 Answer

6 votes

Answer:

import java.util.Scanner;

public class TestClock {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter number of prices");

int numberOfPrizes = in.nextInt();

System.out.println("Enter number of participants");

int numberOfParticipants = in.nextInt();

boolean isDivisible;

if(numberOfPrizes%numberOfParticipants==0){

isDivisible=true;

System.out.println("True");

}

else {

isDivisible=false;

System.out.println("False");

}

}

}

Step-by-step explanation:

Using Java Language;

  1. Prompt user to enter the number of prices and number of participants using the scanner class
  2. receive and save values in the variables numberOfPrizes and numberOfParticipants
  3. Create a boolean variable (isDivisible)
  4. Using if statement and the modulo operator (%) which returns the remainder of division check if numberOfPrizes divieds evenly by numberOfParticipants.
User Sdaz MacSkibbons
by
5.4k points