【发布时间】:2021-07-21 06:51:46
【问题描述】:
所以目标是根据用户的输入计算3个月后累积的利息金额(10%)。但是,我收到了太多错误。为什么?
import java.util.Scanner;
public class showCase {
public static void main(String[]args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
for(i=0; i<3; i++) {
int x = ((amount * 10) / 100);
int result = amount - x;
amount = result;
}
System.out.println(result);
}
}
./Playground/showCase.java:7: error: cannot find symbol
for(i=0; i< 3; i++) {
^
symbol: variable i
location: class showCase
./Playground/showCase.java:7: error: cannot find symbol
for(i=0; i< 3; i++) {
^
symbol: variable i
location: class showCase
./Playground/showCase.java:7: error: cannot find symbol
for(i=0; i< 3; i++) {
^
symbol: variable i
location: class showCase
./Playground/showCase.java:12: error: cannot find symbol
System.out.println(result);
^
symbol: variable result
location: class showCase
4 errors
【问题讨论】:
-
阅读错误,它们准确地告诉您缺少什么。对于
result,请查看this。 -
您缺少
i的变量声明。此外,result在 for 循环内声明,因此超出了 for 循环外的System.out.println()的范围。 -
哪一部分没有找到符号
i,因为你没有在任何地方声明它是要理解的? -
int x = ((amount * 10) / 100);- 你会遇到整数除法的问题
标签: java for-loop calculator