public class exercisel1{
时间: 2024-03-26 08:36:16 浏览: 10
好的,那么在这个类中,可以添加以下方法:
```
public static void main(String[] args) {
// 程序的主函数
}
public void method1() {
// 方法1的具体实现
}
public int method2(String str) {
// 方法2的具体实现
return 0;
}
public String method3(int num) {
// 方法3的具体实现
return "";
}
```
当然,这只是一些示例方法,具体实现根据您的需求来编写。
相关问题
补全public class exereisel{ intx,y; public exercisel (){} public exercisel (int x,int y){ —————————————————— } public exercisel (exercisel p){ —————————————————— } public exercise1 getLocation ( ){ exercisel p=______; //实例exercise1 对象 p,其坐标是(x,y) _______//返回对象 p } public String toString (){ return " (" +x+"," +y+")"; } public static void main ( String ] args ){ exercisel p=___________; System. out. println ("x=”+p.x+" y=" +p.y); System. out. println (" Location is" +p. getlocation () ); }
好的,这里是完整的代码:
```
public class exercisel {
int x, y;
public exercisel() {}
public exercisel(int x, int y) {
this.x = x;
this.y = y;
}
public exercisel(exercisel p) {
this.x = p.x;
this.y = p.y;
}
public exercise1 getLocation() {
exercise1 p = new exercise1();
p.x = this.x;
p.y = this.y;
return p;
}
public String toString() {
return " (" + x + "," + y + ")";
}
public static void main(String[] args) {
exercisel p = new exercisel(1, 2);
System.out.println("x=" + p.x + " y=" + p.y);
System.out.println("Location is" + p.getLocation());
}
}
```
其中,`exercise1` 类没有给出,你需要根据上下文自行推测其定义。
编写一个程序,向一个名为Exercisel7_05.dat的文件中存储一个含5个int值1,2,3,4,5的数组,一个表示当前时间的Date对象,以及一个double值5.5用java
好的,以下是使用Java语言编写的程序,可以实现您的要求:
```java
import java.io.*;
import java.util.*;
public class Exercise {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
double d = 5.5;
Date now = new Date();
try {
FileOutputStream fos = new FileOutputStream("Exercisel7_05.dat");
DataOutputStream dos = new DataOutputStream(fos);
for (int i = 0; i < arr.length; i++) {
dos.writeInt(arr[i]);
}
dos.writeLong(now.getTime());
dos.writeDouble(d);
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
运行程序后,会在当前目录下生成一个名为Exercisel7_05.dat的二进制文件,文件中包含了一个int数组、一个Date对象和一个double值,它们的数据分别是{1, 2, 3, 4, 5}、当前时间和5.5。注意,程序中使用了Java的IO类和Date类来实现文件的写入和日期的获取。其中,使用了DataOutputStream类来将数据以二进制形式写入文件。