You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
psckwxi8l 6bb791239c
Update README.md
2 years ago
README.md Update README.md 2 years ago

README.md

java

高级特性IO流 package step4;

import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException;

public class Task {

public void task() throws IOException{
	/********* Begin *********/
	FileReader fr = new FileReader("src/step4/input/input.txt");
	FileWriter fw = new FileWriter("src/step4/output/output.txt");
	int len = 0;
	char[] cbuf = new char[1024];
	while ((len = fr.read(cbuf))!=-1) 
	{
		fw.write(cbuf,0,len);
	}
	fr.close();
	fw.flush();
	fw.close();
	
	FileInputStream fs = new FileInputStream("src/step4/input/input.jpg");
	FileOutputStream fos = new FileOutputStream("src/step4/output/output.jpg");
	int le = 0;
	byte[] bt = new byte[1024];
	while ((le = fs.read(bt))!=-1)
	{
		fos.write (bt,0,le);
	}
	fs.close();
	fos.flush();
	fos.close();	
	/********* End *********/		
}

}

分支结构 package step4;

import java.util.Scanner;

public class HelloSwitch { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

	System.out.println("请输入月份:");
	
	int input = sc.nextInt();	//获取输入的月份
	
    //通过输入的月份来判断当前季节并输出
	/*****start*****/

switch (input) {
case 1:
System.out.println(input+"月是冬天");
break;
case 2:
System.out.println(input+"月是冬天");
break;
case 3:
System.out.println(input+"月是春天");
break;
case 4:
System.out.println(input+"月是春天");
break;
case 5:
System.out.println(input+"月是春天");
break;
case 6:
System.out.println(input+"月是夏天");
break;
case 7:
System.out.println(input+"月是夏天");
break;
case 8:
System.out.println(input+"月是夏天");
break;
case 9:
System.out.println(input+"月是秋天");
break;
case 10:
System.out.println(input+"月是秋天");
break;
case 11:
System.out.println(input+"月是秋天");
break;
case 12:
System.out.println(input+"月是冬天");
break;

}

	/*****end*****/
	
}

}

package step4;

import java.util.Scanner;

public class HelloSwitch { public static void main(String[] args) { Scanner sc = new Scanner(System.in);

	System.out.println("请输入月份:");
	
	int input = sc.nextInt();	//获取输入的月份
	
    //通过输入的月份来判断当前季节并输出
	/*****start*****/

switch (input) {
case 1:
System.out.println(input+"月是冬天");
break;
case 2:
System.out.println(input+"月是冬天");
break;
case 3:
System.out.println(input+"月是春天");
break;
case 4:
System.out.println(input+"月是春天");
break;
case 5:
System.out.println(input+"月是春天");
break;
case 6:
System.out.println(input+"月是夏天");
break;
case 7:
System.out.println(input+"月是夏天");
break;
case 8:
System.out.println(input+"月是夏天");
break;
case 9:
System.out.println(input+"月是秋天");
break;
case 10:
System.out.println(input+"月是秋天");
break;
case 11:
System.out.println(input+"月是秋天");
break;
case 12:
System.out.println(input+"月是冬天");
break;

}

	/*****end*****/
	
}

}

数组 package step2;

import java.util.Scanner;

public class HelloWorld { public static void main(String[] args) {

	/********** Begin **********/
	//在这里定义一个长度为4的字符串数组用来存放学生姓名

String[] stuNames = new String[]{"张三","张无忌","张三丰","张岁山"} ;

	//在这里给stuNames数组赋值  分别为   张三,张无忌,张三丰,张岁山
	
	
	
	//在这里输出stuNames数组中的数据
	System.out.println("数组中的第一个数据为:" + stuNames[0]);
	System.out.println("数组中的第二个数据为:" + stuNames[1]);
	System.out.println("数组中的第三个数据为:" + stuNames[2]);
	System.out.println("数组中的第四个数据为:" + stuNames[3]);
	
	
	int[] scores;
	Scanner sc = new Scanner(System.in);
	//在这里使用Scanner获取系统输入的整数,并用获取到的数据来设置scores数组的长度
	int length = sc.nextInt();      ;
	scores = new int[length];           ;
	/********** End **********/
	
	System.out.println("数组scores的长度为" + scores.length);
}

}

对象封装 package case1;

public class TestPersonDemo { public static void main(String[] args) { /********* begin / // 声明并实例化一Person对象p Person p = new Person(); // 给p中的属性赋值 p.setName("张三"); p.setAge(18); // 调用Person类中的talk()方法 p.talk(); / end *********/

}

}

// 在这里定义Person类 class Person { /********* begin *********/

private String name;
private int age;
public String getNmae(){
	return name;
}
public void setName(String name){
	this.name = name;
}
public int getAge(){
	return age;
}
public void setAge(int age){
	this.age = age;
}
public void talk(){
	System.out.println("我是:"+name+",今年:"+age+"岁");
}
/********* end *********/

}

package case2;

public class extendsTest { public static void main(String args[]) { // 实例化一个Cat对象设置属性name和age调用voice()和eat()方法,再打印出名字和年龄信息 /********* begin / Cat cat = new Cat(); cat.name = "大花猫"; cat.age = "6岁"; cat.voice(); cat.eat(); System.out.println(cat.name+cat.age); / end *********/

	// 实例化一个Dog对象设置属性name和age调用voice()和eat()方法,再打印出名字和年龄信息
	/********* begin *********/
	Dog dog  = new Dog();
	dog.name = "大黑狗";
	dog.age = "8岁";
	dog.voice();
	dog.eat();
	System.out.println(dog.name+dog.age);

	/********* end *********/

}

}

class Animal { /********* begin / String name; String age; / end *********/

}

class Cat extends Animal { // 定义Cat类的voice()和eat()方法 /********* begin *********/

public void voice(){
	System.out.println(name+"喵喵叫");
}
public void eat(){
	System.out.println(name+"吃鱼");
}
/********* end *********/

}

class Dog extends Animal { // 定义Dog类的voice()和eat()方法 /********* begin / public void voice(){ System.out.println(name+"汪汪叫"); } public void eat(){ System.out.println(name+"吃骨头"); } / end *********/ }

package case7;

public class interfaceTest { public static void main(String[] args) { // 实例化一Student的对象s并调用talk()方法,打印信息 /********* begin / Student s = new Student(); s.talk(); / end *********/

}

}

// 声明一个Person接口并在里面声明三个常量name、age和occupation并分别赋值声明一抽象方法talk() interface Person { /********* begin *********/ String name = "张三"; int age = 18; String occupation = "学生"; public abstract void talk();

/********* end *********/

}

// Student类继承自Person类 复写talk()方法返回姓名、年龄和职业信息 class Student implements Person {

/********* begin *********/
public void talk() {
    System.out.println("学生——>姓名:"+name+",年龄:"+age+",职业:"+occupation+"");
}
/********* end *********/

}

线程 package step1;

//请在此添加实现代码 /********** Begin / public class ThreadClassOne extends Thread{ public int i=0; public ThreadClassOne(){ super(); } public void run(){ for(i=0;i<10;i++){ if(i%2==1) System.out.print(i+" "); } } } / End **********/

package step1;

//请在此添加实现代码 /********** Begin / public class ThreadClassTwo implements Runnable{ public int i=0; private Thread mythread; public void run(){ for(i=0;i<11;i++){ if(i%2==0) System.out.print(i+" "); } } } / End **********/