public class Example04{
public static void main(String[] args){
final int SIZE=15;
for(int x=1;x<=SIZE;x++){
for(int y=1;y<=SIZE;y++){
int z=x*y;
if(z<10) System.out.println("");
if(z<10) System.out.println("");
System.out.println(""+z);
}
System.out.println(""+z);
}
}
}D:\Java_Exercise\Example04.java:11: 找不到符号
符号: 变量 z
位置: 类 Example04
System.out.println(""+z);
^
1 错误
public static void main(String[] args){
final int SIZE=15;
for(int x=1;x<=SIZE;x++){
for(int y=1;y<=SIZE;y++){
int z=x*y;
if(z<10) System.out.println("");
if(z<10) System.out.println("");
System.out.println(""+z);
}
System.out.println(""+z);
}
}
}D:\Java_Exercise\Example04.java:11: 找不到符号
符号: 变量 z
位置: 类 Example04
System.out.println(""+z);
^
1 错误
变量z超出作用范围
建议修改成:
if(z <10) System.out.print (" ");
System.out.print(""+z);
}
System.out.println();
public static void main(String[] args) {
final int SIZE = 15;
for (int x = 1; x <= SIZE; x++) {
for (int y = 1; y <= SIZE; y++) {
int z = x * y;
if (z < 10)
System.out.println("");
if (z < 10)
System.out.println("");
System.out.println("" + z);
}
System.out.println("" + z);
}
}
}你第二次输出z时,已经不在z的作用域了。
public static void main(String[] args) {
final int SIZE = 15;
for (int x = 1; x <= SIZE; x++) {
for (int y = 1; y <= SIZE; y++) {
int z = x * y;
if (z < 10)
System.out.println("");
if (z < 10)
System.out.println("");
System.out.println("" + z);
}
System.out.println("" + z);
}
}
}你第二次输出z时,已经不在z的作用域了。