public class ValueDemo1{
//主入口
public static void main(String[] args){
//1.基本用法
//定义变量,在进行输出
int a=10;
System.out.println(a); //10
System.out.println(a); //10
System.out.println(a); //10
double b=27.9;
System.out.println(b); //27.9
System.out.println(b); //27.9
System.out.println(b); //27.9
//2.变量参与计算
int c=40;
int d=60;
double e=55.5;
double f=54.5;
System.out.println(c+d); //100
System.out.println(e+f); //110
//修改变量记录的值
a=100;
System.out.println(a); //100
b=110;
System.out.println(b); //110
//整数
System.out.println("------------------------------------");
//注意事项
//在一条语句中,可以定义多个变量
int h=100,j=200,k=300;
System.out.println(h);
System.out.println(j);
System.out.println(k);
//变量在使用之前必须要赋值
int l;
l=500;
//建议:以后在定义变量的时候,请直接赋值
//不要把赋值分开写
System.out.println(l);
//浮点数
System.out.println("------------------------------------");
double m=35.8 ,n=67.9,v=78.8;
System.out.println(m);
System.out.println(n);
System.out.println(v);
int x;
x=500;
System.out.println(x);
}
}
命令行:
C:\新建文件夹>javac ValueDemo1.java
C:\新建文件夹>java ValueDemo1
10
10
10
27.9
27.9
27.9
100
110.0
100
110.0
------------------------------------
100
200
300
500
------------------------------------
35.8
67.9
78.8
500