Welcome to OStack Knowledge Sharing 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 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...