Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

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

public static void main(String[] args) {
    int num1 = 1;
    int num2 = 1;
    int result = num1 * num2; 
    System.out.println("%d x %d = %d
",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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try

System.out.println(num1+" x "+num2+" = "+result+"
");

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
",num1,num2,result);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...