+ 1
My code is error
I want to use the remainder but I do not know how to use it. I want to divide two numbers..if the remainder=0, print "Equal" but if the remainder≠0, print"Not Equal" https://code.sololearn.com/c89YQ7QD6Qpo/?ref=app
3 odpowiedzi
+ 3
Your mistake is that in scanner where u written
Scanner sc = new Scanner (System.in)
Here your object is sc and u when u taking input u have written
input .nextInt() here instead of input u need to write sc.
then u have declared variable a ,b d here its ok but when u taking inout u again writing
int a=sc.nextInt() here remove int if u already decleared with data type.
Same do for second number
Then in if condition u have written d=0 which is not a condition here u assigning value 0 to d u need to use equality operator == double equal rest of the things are ok
+ 3
Inactive I understand. Thank you!
+ 1
import java.util.*;
public class Main {
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter the number of slices of watermelon: ");
int a = sc.nextInt();
System.out.println("Enter the number of friends: ");
int b = sc.nextInt();
int d = (a%b);
if (d == 0)
{
System.out.println("Equal");
}
else
{
System.out.println("Not Equal");
}
}
}