English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write an expression that evaluates to true if the value of the integer variable widthOfBox is not divisible (with no remainder) by the integer variable widthOfBook . Assume that widthOfBook is not zero.

2006-09-01 12:40:58 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

is there any way doing this without using the if command?

2006-09-01 12:54:40 · update #1

one other thing that made me confused is how can a number can't be divided if it has a remainder of 0? All number which can be divided has a remainder of 0?

2006-09-01 13:01:39 · update #2

3 answers

You can use the modulus operator, "%". It calculates the remainder of dividing one number by another.

For example, 21 % 4 evaluates to 1. Since 21 divided by 4 equals 5 plus a remainder of 1.


So in your example, you'd write

if(widthOfBox % widthOfBook!=0) {

//do whatever
}


Does that help?

2006-09-01 12:49:02 · answer #1 · answered by Ox Cimarron 2 · 0 0

if(((int)widthOfBox % (int)widthofBook)==0)
{
//Statements which are 2 be executed when there is no remainder
}

else
{
//Statement which are 2 be executed when there is a remainder
}

if u don't wish 2 use if clause:

(int)widthOfBox % (int)widthOfBook == 0? //Statement when there is no remainder : //Statement when there is remainder

2006-09-01 21:57:42 · answer #2 · answered by Logic 2 · 0 0

how's
(int)woBox % (int)woBook == 0? System.out.println("yes"):Sop("no");
do for you?

2006-09-01 21:47:56 · answer #3 · answered by Andy T 7 · 0 0

fedest.com, questions and answers