java--基本语法1

http://java.chinaitlab.com/Special/shijian/Index.html

 

/*
简单的 HelloWorld 程序
*/
public class Hello{
//main方法
public static void main (String args[]) {
System.out.println (
"Hello World!"); //输出字符串“Hello World!”
}
}

实列

 

代码
public class Assign {
public static void main (String args []) {

// 声明整数型变量
int x,y;

// 声明并赋值给一个单精度浮点数变量
float z = 3.414f;

// 声明并赋值给一个双精度浮点数变量
double w = 3.1415;

// 声明并赋值给一个布尔类型的变量
boolean truth = true;

// 声明字符型变量
char c;

// 声明字符串型变量
String str;

//声明并赋值给一个字符串型变量
String str1 = "bye";

// 为字符型变量复值
c = 'A';

// 给字符串型变量赋值
str = "Hi out there!";

// 给整型变量赋值
x = 6;
y
= 1000;
}
}

 

posted on 2010-08-02 16:36  lovening  阅读(130)  评论(0编辑  收藏  举报