《Java参考大全》之二
来源:互联网 发布:淘宝店铺装修上传宝贝 编辑:程序博客网 时间:2024/05/21 22:29
1、
/*
This is a simple java program.
Call this file "Example.java".
*/
class Example{
//Your program begins with a call to main().
public static void main(String args[]){
System.out.println("This is a simple Java program.");
}
}
2、
/*
Here is another short example.
Call this file "Example2.java".
*/
class Example2 {
public static void main(String args[]) {
int num;//this declares a variable called num
num=100;//this assigns num the value 100
System.out.println("This is num:" + num);
num=num*2;
System.out.print("This value of num*2 is ");
System.out.println(num);
}
}
3、
/*
Demonstrate the if.
Call this file "IfSample.java".
*/
class IfSample {
public static void main(String args[]) {
int x,y;
x=10;
y=20;
if(x<y)System.out.println("x is less than y");
x=x*2;
if(x==y) System.out.println("x now equal to y");
x=x*2;
if(x>y) System.out.println("x now equal to y");
//this won't display anything
if(x==y) System.out.println("you won't see this");
}
}
4、
/*
Demonstrate the for loop.
Call this file "ForTest.java".
*/
class ForTest {
public static void main(String args[]){
int x;
for (x=0;x<10;x=x+1)
System.out.println("This is x:"+x);
}
}
5、
/*
Demonstrate a block of code.
Call this file "BlockTest.java"
*/
class BlockTest {
public static void main(String args[]){
int x,y;
y=20;
//the target of this loop is a block
for(x=0;x<10;x++){
System.out.println("This is x:"+x);
System.out.println("This is y:"+y);
y=y-2;
}
}
}
- 《Java参考大全》之二
- 《Java参考大全》之一
- java类型转换参考大全
- java类型转换参考大全
- JAVA启动参数大全之二:非标准参数
- JAVA启动参数大全之二:非标准参数[收藏]
- JAVA启动参数大全之二:非标准参数
- JAVA启动参数大全之二:非标准参数
- JAVA启动参数大全之二:非标准参数
- JAVA启动参数大全之二:非标准参数[收藏]
- JAVA启动参数大全之二:非标准参数
- 参考大全
- ADO API 参考( ADO方法)之二
- Delphi背后---初学者参考之二(1)
- Delphi背后---初学者参考之二(2)
- Delphi背后---初学者参考之二(1)
- Delphi背后---初学者参考之二(2)
- Net 服务命令行参考之二
- java2入门经典(读书笔记)
- 用mod_jk2.so配置apache2.0.48和Tomcat5.0.19(转)
- 從DataSet到Excel
- 從DataSet到Excel
- 使用标签创建下拉列表和多选列表框
- 《Java参考大全》之二
- 页面自动刷新
- 软件版本号详解(转)
- 真正的Java学习从入门到精通
- 嵌入式linux的tftp安装配置
- c# 删除记事本某一行
- 以可靠性为中心的维修(RCM)
- MVC
- 疑难业务逻辑SQL中巧解。