62,628
社区成员
发帖
与我相关
我的任务
分享package taotao.montao.over;
public class TestNum {
public static void main(String[] args) {
int[] num = work(10, 20);
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
}
public static int[] work(int start, int end) {
int[] num = new int[end-start+1];
int j = 0;
for (int i = start; i < end+1; i++) {
num[j] = i * i;
j++;
}
return num;
}
}
package taotao.montao.over;
import java.io.*;
public class FileTest {
public static void main(String[] args) {
System.out.println(work());
}
public static String work() {
String msg = null;
File file1 = new File("H:/file1.txt");
File file2 = new File("H:/file2.txt");
BufferedReader br = null;
String fileContent = "";
// 判断是否存在
if (file1.exists() && file2.exists()) {
// 读出file1中的内容
try {
br = new BufferedReader(new FileReader(file1));
String line = "";
while ((line = br.readLine())!= null) {
fileContent += line;
}
msg = "文件COPY已经成功!";
} catch (Exception e) {
e.printStackTrace();
msg = "当前目录下不存在该文件或则读写失败!";
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//写文件
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(file2));
bw.write(fileContent);
} catch (Exception e) {
e.printStackTrace();
}finally
{
try {
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return msg;
}
}
package taotao.montao.over;
public class StudentTest {
public static void main(String[] args) {
Student student1 = new Student(101,"montao",85.5f);
Student student2 = new Student(102,"yangtao",98.5f);
Student student3 = new Student(103,"taotao",87.7f);
Object[] object = {student1,student2,student3};
//打印
for(int i=0;i< object.length;i++)
{
Student stu = (Student)object[i];
System.out.println("----------学员信息----------");
System.out.println("学员ID:"+stu.getStudentId());
System.out.println("学员姓名:"+stu.getStudentName());
System.out.println("学员分数:"+stu.getMark());
}
}
}
class Student
{
private int studentId;
private String studentName;
private float mark;
public Student(int id,String name,float mark)
{
this.studentId = id;
this.studentName = name;
this.mark = mark;
}
public int getStudentId()
{
return this.studentId;
}
public String getStudentName()
{
return this.studentName;
}
public float getMark()
{
return this.mark;
}
}
package taotao.montao.over;
public class TestJieChen {
public static void main(String[] args) {
System.out.println(cunt(5));
}
public static int cunt(int num)
{
int result = 1;
if(num>0)
{
int i = 1;
while(i<=num)
{
result = result*num;
i++;
}
}
return result;
}
}
package taotao.montao.over;
public class Rectangle {
public static void main(String[] args) {
CreateRectangle rectangle = new CreateRectangle(40,50);
int area = rectangle.getArea();
System.out.println("面积是: "+area);
}
}
class CreateRectangle {
int width = 0;
int height = 0;
public CreateRectangle(int width, int height) {
this.width = width;
this.height = height;
}
public int getArea()
{
int area = 0;
area = this.height * this.width;
return area;
}
}