类型PrintStream的方法println(int)不适用于参数(字符串,整数,整数,整数) [英] The method println(int) in the type PrintStream is not applicable for the arguments (String, int, int, int)

查看:190
本文介绍了类型PrintStream的方法println(int)不适用于参数(字符串,整数,整数,整数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在尝试打印出类似"1 * 10 = 10"的表格.但是我得到一个错误:

I am trying to printout a form like "1 * 10 = 10". However I get an error:

PrintStream类型的方法println(int)不适用于参数(字符串,整数,整数,整数)".

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?

推荐答案

尝试

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.

更快的方法:

System.out.printf("%d x %d = %d\n",num1,num2,result);

这篇关于类型PrintStream的方法println(int)不适用于参数(字符串,整数,整数,整数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆