class Demo
{
public static void main(String[] args)
{
System.out.println("hello E盘");
}
}
class Demo
{
public static void main(String[] args)
{
System.out.println("hello E盘");
}
}
/*
需求:练习一个hello world程序。
思路:
1,定义一个类,因为java程序都定义类中,java
程序都是以类的形式存在的,类的形式其实就是一个字节码文件最终体现。
2,定义一个主函数。为了让该类可以独立运行。
3,因为
演示hello world,在控制台上看到该字样,所以需要使用输出语句完成。
步骤:
1,用class关键字来完成类的定义,并起一个阅读性强的类名。
2,主函数:public static void main(String[] args)这时固定格式的。jvm认识。
3,使用输出语句:System.out.println("hello world");
代码仅仅是思想的一种体现形式。
*/
class Demo
{
//定义一个主函数,为了保证程序的独立运行。
public static void main(String[] args)
{
System.out.println("hello world");//这是输出语句,用于将括号中的数据打印到控制台上,ln可以在数据的结尾处换行。
}
}
class OperateDemo
{
public static void main(String[] args)
{
//算术运算符。 + - * / %(取余,模运算) +(连接符)
// ++(自增:就在原有数据基础上+1,在赋给原有数据) --
//int x = 6370;
//x = x / 1000 * 1000;
//System.out.println(x);
// System.out.println(5%2);
// System.out.println(3+"2");
//System.out.println("5+5="+(5+5));//"5+5=5"+5 "5+5=55"
//int a = 4,b = 5;
//System.out.println("a="+a+",b="+b);//a=4,b=5;
int a = 3,b;
//a++;//a = a+1;
// b = a++;
b = (a++)+(++a)+(a++)+a;
// 3 5 5 6
System.out.println("a="+a+",b="+b);
int i = 3;
i = i++;
System.out.println("i="+i);
}
}
class OperateDemo2
{
public static void main(String[] args)
{
//赋值运算符。= += -= *= /= %=
// int a,b,c;
// a = b = c = 4;
//int a = 4;
//a+=2;//a = a + 2;
short s = 3;
//s+=4;
s = (short)(s + 4);
System.out.println("s="+s);
}
}
class VarDemo
{
public static void main(String[] args)
{
//数据类型 变量名 = 初始化值;
byte b = 3;
short s = 4000;
int x = 12;
long l = 123l;
float f = 2.3f;
double d = 3.4;
char ch = '1';
boolean bl = true;
bl = false;
{
int z = 9;
System.out.println(z);
}
System.out.println(z);
//System.out.println(y);
}
}
class VarDemo2
{
public static void main(String[] args)
{
// int x = 3;
// byte b = 5;
// x = x + b;
// byte b = 3;
// b = (byte)(b + 200);//强制类型转换。
//System.out.println((char)('a'+1));
// System.out.println('你'+0);//unicode国际标准码表。
byte b = 4;
//b = 3+7;
byte b1 = 3;
byte b2 = 7;
//b2 = 127;
int x;
//b = b1 + b2;
int x1 =Integer.MAX_VALUE ;
int x2 =2;
x = x1+x2;
//System.out.println(x);
int n = 8;
n = 9;
n = 19;
//System.out.println(n);
}
}
class DoWhileDemo
{
public static void main(String[] args)
{
/*
do
{
执行语句;
}while(条件表达式);
*/
int x = 1;
do
{
System.out.println("x="+x);
x++;
}
while (x<1);
/*
do while语句的特点:无论条件是否满足,循环体至少执行一次。
*/
int y = 1;
while(y<1)
{
System.out.println("y="+y);
y++;
}
}
}
class ForDemo
{
public static void main(String[] args)
{
/*
for(初始化表达式;循环条件表达式;循环后的操作表达式)
{
执行语句;(循环体)
}
for(int x = 1; x<3; x++)
{
System.out.println("x="+x);
}
*/
int x = 1;
for(System.out.println("a");x<3; System.out.println("c"))
{
System.out.println("d");
x++;
}
// for(int a=0,b=0; a<3; a++,b--)
//a d c d c
}
}
class ForTest
{
public static void main(String[] args)
{
/*