Java – Method println (int) in printstream type is not applicable to parameters (string, int, int, int)
•
Java
public static void main(String[] args) {
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'm trying to print out a form like "1 * 10 = 10" But I received an error:
I don't know what the problem is. How can I change it?
Solution
attempt
System.out.println(num1+" x "+num2+" = "+result+"\n");
Update: some people say this connection method is slower than others You're right. It's slower, but is this example really important?
This method is usually used for debugging, not as part of the final code. It is usually done only once or twice for the whole code
Faster method:
System.out.printf("%d x %d = %d\n",result);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码