Java小程序代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java小程序代码
/**第一个程序*/
public class Welcome
{
public static void main(String[] args)
{
System.out.println("这是你的第一个程序,欢迎你走入Java的大门");
}
}
/**学生信息导入*/
class StudentTest
{
public static void main(String[] args)
{
Student aStudent = new Student();
aStudent.setName("张楠");
aStudent.setStudentNum("20030408");
System.out.println("学生的姓名是:" + aStudent.getName() + ",学号是:" + aStudent.getStudentNum());
}
}
class People
{
private String name;
public String getName(){
return name;
}
public void setName(String strName)
{
name = strName;
}
}
class Student extends People
{
private String studentNum;
public String getStudentNum()
{
return studentNum;
}
public void setStudentNum(String strStudentNum) {
studentNum = strStudentNum;
}
}
/**移位运算符测试 */
public class BitMotion
{
public static void main(String[] args)
{
int a = 15;
int b = 2;
int x = a << b;
int y = a >> b;
int z = a >> b;
System.out.println(a + "<<" + b + "=" + x); System.out.println(a + ">>" + b + "=" + y); System.out.println(a + ">>>" + b + "=" + z); }
}
/*
*测试位的四种运算
*/
public class BitOperation
{
public static void main(String[] args)
{
int a = 15;
int b = 2;
int x = a & b;
int y = a | b;
int z = a ^ b;
int r = ~x;
System.out.println(a + "&" + b + "=" + x); System.out.println(a + "|" + b + "=" + y); System.out.println(a + "^" + b + "=" + z); System.out.println("~" + x + "=" + r);
}
}
/*
*测试boolean型数据
*/
public class BooleanTest
{
public static void main(String[] args) {
int a = 20;
int b = 30;
boolean x, y,z;
x = (a > b);
y = (a < b);
z = ((a + b) == 50);
System.out.println("x=" + x);
System.out.println("y=" + y);
System.out.println("z=" + z);
}
}
/*
*测试不同数制表现形式及系统的自动转化功能
*/
public class ByteTest
{
public static void main(String[] args)
{
byte x = 22;//十进制
byte y = 022;//八进制
byte z = 0X22;//十六进制
System.out.println("转换成十进制,x=" + x); System.out.println("转换成十进制,y=" + y); System.out.println("转换成十进制,z=" + z); }
}
/*
*测试char型与整数的转换
*/
public class CharTest
{
public static void main(String[] args)
{
char x = 'M';