java - 公共方法不返回变量
问题描述
我是 Java 新手,为什么我的方法没有返回我放置的变量。我想使用我不想使用 sysout 但它不起作用的返回东西。
public static void main(String[] args) {
counter("this is a test");
}
public static int counter(String sentence) {
int count = 0;
while (CODE DELETED){
count=count+1;
MORE CODE DELETED
}
CODE DELETED
return count;
}
解决方案
它确实返回它,但您既不分配值,也不使用它。
尝试这个:
public static void main(String[] args) {
int result = counter("this is a test");
System.out.println("result = " + result);
}
推荐阅读
- jenkins - 如何检查触发 Jenkins Job 的原因?
- android - 静态设置片段中的 setPreferenceScreen() - 刷新设置活动
- javascript - 设置没有删除项目的状态
- powershell - 如何使用 7zip.exe 在 Powershell 中加速解压缩过程
- verilog - 使用 xilinx vivado 2018.2 在 systemverilog 中随机化 32 位值
- git - 合并 git 分支。我的本地分支在许多已移动到 master 上的文件中有数百个小编辑
- c# - DocuSign JWT 身份验证:意外的 PEM 类型
- wordpress - 在本地主机上安装 WordPress
- kdb - KDB - 似乎无法将 csv 文件导入表
- javascript - 每次调用的多个 ajax 调用都会更新变量