java - Concatenating issue when printing out objects with System.out.println();
问题描述
I'm learning to code on Codecademy and keep coming up with a concatenating issue. For example, when I wrote:
System.out.println(lemonadeStand + cookieShop);
I got back the error:
Store.java:32: error: bad operand types for binary operator '+' System.out.println(lemonadeStand + cookieShop);
But when I wrote:
System.out.println(lemonadeStand);
System.out.println(cookieShop);
The code worked. Can someone tell me why doesn't the first one work? (And thanks)
---edit--- Thanks for all the help everyone! This was my first time posting a question here and I'm amazed at how kind and helpful the community is!
解决方案
请在连接两个变量之前,您必须验证它们是相同类型或尝试 System.out.println(first + " " + second);
推荐阅读
- mysql - 如何减少 MySQL 中的整数?
- notepad++ - How can I insert a character before every word in notepad++?
- python-3.x - 将 Conv2D 用于图像有什么问题?
- javascript - Nodejs javascript添加到按钮没有响应
- tensorflow - 神经网络在低密度区域的回归精度
- pyspark - 通过 pyspark 和 pycharm 进行 SQLite JDBC 连接的 jar 文件
- django - 如何在 Django 中使用 Vue 模板?
- mysql - 用于 AJAX 网页的 Linux Web 服务器配置高消耗 CPU
- api - Twitter can_dm 在 Web API 上返回 null
- python-3.x - 使用 Python 3 通过 WIFI 将相机从一个 Raspberry Pi 播放到另一个