
public int remainder(int a, int b)
{
int answer = a % b;
System.out.printf("%d % %d = ", a , b);
return (answer);
}
and in my main,
int answerRemain = calc.remainder (3,4);
System.out.println (answerRemain);
and when i tried running it, it tells me:-
Exception in thread "main" java.util.IllegalFormatFlagsException: Flags = ' '
at java.util.Formatter$FormatSpecifier.checkText(Formatter.java:2945)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2647)
at java.util.Formatter.parse(Formatter.java:2480)
at java.util.Formatter.format(Formatter.java:2414)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
if i take out the % from "%d % %d = ", so that it is "%d %d" then it runs fine and gives the correct answer. my question is why wont it compile and, how can i print out the modulus sign so my output looks like 3 % 4 = 3. thank you!

We have modified your code. The character you want to display in the printf method is actually invalid.Therefore error occurs. Anyways, check your code.
class FindRemainder
{
public int remainder(int a, int b) {
int answer = a % b;
System.out.println(a+" % "+b+" = " +answer);
return (answer);
}
public static void main(String[] args)
{
FindRemainder f=new FindRemainder();
f.remainder(3,4);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.