Bad operand with mod | Sololearn: Learn to code for FREE!

0

Bad operand with mod

% is showing bad operand, is there another symbol that makes mod?

10/15/2021 9:52:12 PM

Joel Brainard

7 Answers

New Answer

+3

If your language don't have a %-operator, just calculate the modulo val a = 5 val b = 3 var x = a / b var mod = a - b * (a / b) Prints x -> 1 mod -> 2

+3

"%" is the modulo operator in Java. But "=" is the assignment operator, you can't use it as a comparison operator. The comparison operator for identity is "==".

+2

It's tough to answer a question when I don't have the code.

+2

number%10 is fine but number%10=0 is not. (Left side expression instead of operand). You must use == operator for comparison.. number%10==0

+1

Don't expect people to put effort into helping you if you're not even willing to put any effort into asking your question. https://www.sololearn.com/Content-Creation-Guidelines? https://code.sololearn.com/Wv5gTHy1N6Ji/?ref=app https://www.sololearn.com/discuss/1316935/?ref=app https://code.sololearn.com/W3uiji9X28C1/?ref=app https://www.sololearn.com/discuss/333866/?ref=app

0

Sorry first question, this was the code, java to be clear import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //your code goes here if (number%10 = 0|| number % 9 = 0) { System.out.println("You won $200"); } else if (number % 4 = 0 || number % 6 = 0) { System.out.println("You won $50"); } else { System.out.println("Try again"); } } }

0

I thought i could use number % 10 To find if the numbers were divisable by 10, 9 ect.