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.
321/新建文本文档.txt

326 lines
7.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

线程
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 step3;
import java.util.Scanner;
public class HelloStep3 {
public static void main(String[] args) {
System.out.println("星级成绩评定系统");
System.out.println("请输入成绩:");
Scanner sc = new Scanner(System.in);
/******start******/
int scope = sc.nextInt();
if(scope >=90) {
System.out.print("*****五星成绩");
} else if(scope>=80 && scope<90) {
System.out.print("****四星成绩");
} else if(scope>=70 && scope<80) {
System.out.print("***三星成绩");
} else if(scope>=60 && scope<70) {
System.out.print("**俩星成绩");
} else {
System.out.print("无星成绩");
}
/******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 step3;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Task {
public void task() throws IOException{
/********* Begin *********/
String file1 = "src/step3/input/input.txt";
FileReader fr = new FileReader(file1);
char[] cbuf = new char[8];
fr.read(cbuf);
String file2 = "src/step3/output/output.txt";
FileWriter fw = new FileWriter(file2);
fw.write(cbuf);
fr.close();
fw.flush();
fw.close();
/********* End *********/
}
}
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 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 *********/
}