最新消息:20210917 已从crifan.com换到crifan.org

【已解决】java代码println报错:The method println(String) in the type PrintStream is not applicable for the arguments (String, String)

Java crifan 2643浏览 0评论
折腾:
【未解决】用Java代码解析104协议收到的数据
期间,尝试去打印变量:
System.out.println("each104DataStr=%s", each104DataStr);
结果提示报错:
The method println(String) in the type PrintStream is not applicable for the arguments (String, String) Java(67108979)
看来System.out.println不支持参数。
那要去找找,有哪些java的print函数,支持参数的。
java The method println(String) in the type PrintStream is not applicable for the arguments (String, String)
java – The method println(double) in the type PrintStream is not applicable for the arguments (String, double) – Stack Overflow
java – The method println(int) in the type PrintStream is not applicable for the arguments (String, int, int, int) – Stack Overflow
用+加号。不方便。
printf才支持参数
试试:
System.out.printf("each104DataStr=%s", each104DataStr);
就没语法错误了:
【总结】
此处java中最常用的 System.out.println 不允许加参数
换用 System.out.printf 就可以加参数了:
System.out.printf("each104DataStr=%s", each104DataStr);
但是打印字符串最后,没有换行。
想要换行,可以
(1)System.out.printf中自己加上\n换行
System.out.printf("each104DataStr=%s\n", each104DataStr);
(2) System.out.println 匹配 加号+
System.out.println("each104DataStr=" + each104DataStr);
就有换行了。
另外,还有个:System.out.format
感觉和System.out.printf一样
举例:
System.out.format("each104DataStr=%s\n", each104DataStr);

转载请注明:在路上 » 【已解决】java代码println报错:The method println(String) in the type PrintStream is not applicable for the arguments (String, String)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.178 seconds, using 23.37MB memory