public class MathTest {
public static void main(String[] args) {
System.out.println(Math.PI);
System.out.println(Math.E);
System.out.println(Math.pow(2, 3));
System.out.println(Math.sqrt(9));
}
}
import java.util.Random;
public class RandomTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*Random ra=new Random();
//创建一个随机数类的对象
for(int i=0;i<20;i++)
{
System.out.println(ra.nextInt(10));
}*/
int[] res=getLottery(33,7);
for(int i=0;i<res.length;i++)
{
System.out.println(res[i]);
}
}
public static int[] getLottery(int max,int count)
{
int[] result=new int[count];//定义用来保存结果的整形数组
Random ra=new Random();
result[0]=ra.nextInt(max)+1;
int i=1;
while(i<=count-1)
{
boolean flag=true;
int temp=ra.nextInt(max)+1;
for(int j=0;j<i;j++)
{
if(temp==result[j])
{
flag=false;
break;
}
}
if(flag==true)
{
result[i]=temp;
i++;
}
}
return result;
//返回结果数组
}
public static int[] getLottery1()
{
int[] result=new int[7];//定义用来保存结果的整形数组
Random ra=new Random();
result[0]=ra.nextInt(33)+1;
int i=1;
while(i<=5)
{
boolean flag=true;
int temp=ra.nextInt(33)+1;
for(int j=0;j<i;j++)
{
if(temp==result[j])
{
flag=false;
break;
}
}
if(flag==true)
{
result[i]=temp;
i++;
}
}
result[6]=ra.nextInt(16)+1;
return result;
//返回结果数组
}
}
import java.io.IOException;
public class RuntimeTest {
public static void main(String[] args) {
Runtime run=Runtime.getRuntime();
//获取虚拟机的进程
try
{
run.exec("notepad.exe");
run.exec("calc.exe");
run.exec("mspaint.exe");
}
catch(IOException ex)
{
System.out.println("程序找不到");
}
}
}
import java.util.Properties;
public class SystemTest {
public static void main(String[] args) {
Properties props=System.getProperties();
//获取系统的所有属性,并保存到Properties对象中
System.out.println("Java的运行环境版本:"+props.getProperty("java.version"));
System.out.println("Java的运行环境供应商:"+props.getProperty("java.vendor"));
System.out.println("Java供应商的URL:"+props.getProperty("java.vendor.url"));
System.out.println("Java的安装路径:"+props.getProperty("java.home"));
System.out.println("Java的虚拟机规范版本:"+props.getProperty("java.vm.specification.version"));
System.out.println("Java的虚拟机规范供应商:"+props.getProperty("java.vm.specification.vendor"));
System.out.println("Java的虚拟机规范名称:"+props.getProperty("java.vm.specification.name"));
System.out.println("Java的虚拟机实现版本:"+props.getProperty("java.vm.version"));
System.out.println("Java的虚拟机实现供应商:"+props.getProperty("java.vm.vendor"));
System.out.println("Java的虚拟机实现名称:"+props.getProperty("java.vm.name"));
System.out.println("Java运行时环境规范版本:"+props.getProperty("java.specification.version"));
System.out.println("Java运行时环境规范供应商:"+props.getProperty("java.specification.vender"));
System.out.println("Java运行时环境规范名称:"+props.getProperty("java.specification.name"));
System.out.println("Java的类格式版本号:"+props.getProperty("java.class.version"));
System.out.println("Java的类路径:"+props.getProperty("java.class.path"));
System.out.println("加载库时搜索的路径列表:"+props.getProperty("java.library.path"));
System.out.println("默认的临时文件路径:"+props.getProperty("java.io.tmpdir"));
System.out.println("一个或多个扩展目录的路径:"+props.getProperty("java.ext.dirs"));
System.out.println("操作系统的名称:"+props.getProperty("os.name"));
System.out.println("操作系统的构架:"+props.getProperty("os.arch"));
System.out.println("操作系统的版本:"+props.getProperty("os.version"));
System.out.println("文件分隔符:"+props.getProperty("file.separator")); //在 unix 系统中是"/"
System.out.println("路径分隔符:"+props.getProperty("path.separator")); //在 unix 系统中是":"
System.out.println("行分隔符:"+props.getProperty("line.separator")); //在 unix 系统中是"/n"
System.out.println("用户的账户名称:"+props.getProperty("user.name"));
System.out.println("用户的主目录:"+props.getProperty("user.home"));
System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
/*String str="abc";
String str1=new String();
String str2=new String("abc");
char[] chs={'a','b','c'};
String str3=new String(chs);
System.out.println("abc"+123);
System.out.println("abc"+String.valueOf(123));
String num="20150602010101";
String strn="a,b,c,d,e,f";
String[] strs=strn.split(",");
System.out.println(strs.length);
showInfo("001,张三,男,21");
StringBuffer strx=new StringBuffer("abcdef");
strx.insert(1, "x");
System.out.println(strx.toString());
System.out.println(covertInfo1("19971001"));*/
String str1="abc";
String str2=" abc";
System.out.println((str1.trim())==(str2.trim()));
System.out.println(str1.trim().equals(str2.trim()));
}
public static void showInfo(String str)
{
String[] strs=str.split(",");
int year=2017-Integer.parseInt(strs[3]);
System.out.println("学号为:"+strs[0]);
System.out.println("姓名为:"+strs[1]);
System.out.println("性别为:"+strs[2]);
System.out.println("出生年份为:"+year);
}
public static String covertInfo(String str)
{
StringBuffer re=new StringBuffer(str);
re.insert(4, "年");
re.insert(7, "月");
return re.toString()+"日";
}
public static String covertInfo1(String str)
{
String str1=str.substring(0,4);
String str2=str.substring(4,6);
String str3=str.substring(6);
return str1+"年"+str2+"月"+str3+"日";
}
}
public class Test2 {
public static void main(String[] args) {
int[] arrs={1,2,3,4,5,6,7};
int[] arrs1=new int[12];
System.arraycopy(arrs, 0, arrs1, 3, 7);
for(int i=0;i<arrs1.length;i++)
{
System.out.println(arrs1[i]);
}
}
}
public class Test1 {
public static void main(String[] args) {
long milis=0L;
for(int i=0;i<=10000;i++)
{
//long temp=0L;
milis=System.currentTimeMillis();
System.out.println(milis);
//milis=temp;
}
}
}
public class Test2 {
public static void main(String[] args) {
int[] arrs={1,2,3,4,5,6,7};
int[] arrs1=new int[12];
System.arraycopy(arrs, 0, arrs1, 3, 7);
for(int i=0;i<arrs1.length;i++)
{
System.out.println(arrs1[i]);
}
}
}
public class Test4 {
public static void main(String[] args) {
System.out.println("程序开始运行");
System.exit(0);
System.out.println("程序结束运行");
}
}