变量声明和赋值
变量用于存储信息。一个变量代表一个特殊类型的存储位置,它指向内存的某个单元,而且指明这块内存有多大。变量的值可以是基本类型,也可以是对象。
下列程序显示了如何声明及赋值整数、浮点、boolean、字符和String类型变量。
public class TestAssign {
public static void main(String args[]) {
int a, b; // declare int variables
float f = 5.89f; // declare and assign float
double d = 2.78d; // declare and assign double
boolean b = true;// declare and assign boolean
char c; // declare character variable
String str; // declare String
String str1 = "good"; // declare and assign String variable
c = 'A'; // assign value to char variable
str = "hello ,hello"; // assign value to String variable
a = 8;
b = 800; // assign values to int variables
}
}
java视频教程请登录http://www.rjpx.net/
http://www.5itjob.com
http://www.rjpx.net