Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method println(int) in the type PrintStream is not applicable for the arguments (String, int, int, int)

Tags:

java

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?

like image 976
user5624516 Avatar asked Dec 01 '15 07:12

user5624516


1 Answers

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);
like image 103
Mayuso Avatar answered Oct 04 '22 22:10

Mayuso