localvariabletest.java
来自「《Java核心技术应用开发》电子工业出版社书籍源代码」· Java 代码 · 共 30 行
JAVA
30 行
/**
* 这个类有编译错误
* 演示了局部变量的使用
*/
package sample;
public class LocalVariableTest {
// int x;
public void correctLocalV() {
int x; //Just declare
int y = 10; //Declare and initiate
x = 20; //Evaluate
int z = x + y; //Declare and initiate
String str = "Hello"; //Declare and initiate
String str1 = new String("World"); //Declare and initiate
char ch; //Just declare
ch = 'c'; //Evaluate
}
public void incorrectLocalV() {
int x, z; //Declare only
int y = 10;
if( y > 20) z = x + y; //x isn't be initiated
String str; //Declare only
String str1 = "Hello" + new String(" World") + str; //str isn't be initiated
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?