📄 localvariabletest.java
字号:
/**
* 这个类有编译错误
* 演示了局部变量的使用
*/
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -