public static void main(String[] args) {
int num1 = 1;
int num2 = 1;
int result = num1 * num2;
System.out.println("%d x %d = %d\n",num1,num2,result);
}
I am trying to printout a form like "1 * 10 = 10". However I get an error:
The method println(int) in the type PrintStream is not applicable for the arguments (String, int, int, int)".
I don't know what's the problem and how should I change it?
Try
System.out.println(num1+" x "+num2+" = "+result+"\n");
UPDATE: Some of you are saying this concatenation method is slower than other methods. You are right, it is slower, but does it really matter for this example?
This method is usually used to debug, not as part of the final code, and usually only once or twice on the whole code.
Faster method:
System.out.printf("%d x %d = %d\n",num1,num2,result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With