- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请帮忙,我是java新手。我必须使用数组、for 和子例程来做作业。这是我到目前为止的代码:
import java.util.*;
import static java.lang.System.out;
public class ventasArreglo{
static int dias, semanas, i, j;
static Scanner kb=new Scanner(System.in);
public static void main(String args[]){
dias=5;
semanas=4;
int mes[][] = new int[semanas][dias];
introducirDatos();
}
static void introducirDatos(){
for(i=0;i<semanas;i++){
for(j=0;j<dias;j++){
out.println("Cantidad de Ventas");
mes[i][j]=kb.nextInt();
}
}
}
}
但编译后我不断收到此错误: 发现 1 个错误:[行:20]
Error: cannot find symbol
symbol: variable mes
location: class ventasArreglo
最佳答案
变量 mes
的声明应移至外部,以便静态方法 introducirDatos
可见:
static int dias, semanas;
static int[][] mes;
public static void main(String[] args) {
dias=5;
semanas=4;
mes = new int[semanas][dias];
introducirDatos();
}
static void introducirDatos(){
Scanner kb=new Scanner(System.in);
for(int i=0;i<semanas;i++){
for(int j=0;j<dias;j++){
out.println("Cantidad de Ventas");
mes[i][j]=kb.nextInt();
}
}
}
此外,Scanner
应该移动到实际需要的方法内部,而不是在顶层将其声明为静态。循环计数器也不必位于顶层。
但是为什么要使用静态导入呢?我们应该谨慎使用它们。正如 doc 中提到的:
So when should you use static import? Very sparingly! Only use it when you'd otherwise be tempted to declare local copies of constants, or to abuse inheritance (the Constant Interface Antipattern). ... If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import.
检查这个link也是如此。
关于java - 错误: cannot find symbol symbol: variable mes location: class ventasArreglo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32877473/
请帮忙,我是java新手。我必须使用数组、for 和子例程来做作业。这是我到目前为止的代码: import java.util.*; import static java.lang.System.ou
我是一名优秀的程序员,十分优秀!