0

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

15th Oct 2021, 9:52 PM
Joel Brainard
+ 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
15th Oct 2021, 10:30 PM
Coding Cat + 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 "==".
16th Oct 2021, 1:01 AM
Simon Sauter + 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
16th Oct 2021, 3:49 PM
Jayakrishna 🇮🇳 15th Oct 2021, 9:56 PM
Simon Sauter 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"); } } }
15th Oct 2021, 10:34 PM
Joel Brainard
0
I thought i could use number % 10 To find if the numbers were divisable by 10, 9 ect.
15th Oct 2021, 10:35 PM
Joel Brainard