Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java方法中执行数学运算?_Java_Math - Fatal编程技术网

如何在java方法中执行数学运算?

如何在java方法中执行数学运算?,java,math,Java,Math,我正在尝试创建一个元音计数器。我已经声明了int numVowels和numConsanants。如何将它们相加,然后使用printVarValue打印出来。我已经尝试过了 int Varvalue = numVowels + numConstants; int Varvalue = numVowels * numConstants; 错误不能使用两个变量值 问题是,您两次声明同一个变量: int Varvalue = numVowels + numConstants; int Varvalu

我正在尝试创建一个元音计数器。我已经声明了int numVowels和numConsanants。如何将它们相加,然后使用printVarValue打印出来。我已经尝试过了

int Varvalue = numVowels + numConstants;
int Varvalue = numVowels * numConstants;
错误不能使用两个变量值


问题是,您两次声明同一个变量:

int Varvalue = numVowels + numConstants;
int Varvalue = numVowels * numConstants;
^ this variable name is already used, you cannot declase it again

只需将第二个变量的名称更改为其他名称(最好是有意义的)。

您声明了同一个变量两次。将代码更改为:

int varValue = numVowels + numConstants;

int varValue2 = numVowels * numConstants;


请出示你的密码好吗?你面临的问题是什么?变量名已经被使用,你不能再声明它-从下面复制答案如果这真的是唯一的问题,那么这是一个打字错误的问题,你应该投票关闭,而不是回答。更改第二个变量的名称-或删除
int
以重新为其分配新值。@ScaryWombat如果将其更改为另一个变量,则可将其打印。还有更多步骤,如从numConstants获取答案并减去5如何将其连接在一起以打印?如果我想把答案减去5?
int varValue = numVowels + numConstants;

varValue = numVowels * numConstants;//this varValue will overwrite value from first equation, so this makes no sence