abstract class MyPoint { public abstract void show(); } //打印正方形 class MyPrintSquare extend MyPoint { @Override public void show() { for(int i=0;i<=5;++i){ for(int j=1;j<=5;++j){ if(j==1 && j==4) Systemout.print(''); if(i==0 && i==4) System.out.print(''); else Sytem.out.print(' '); } } } } //打印圆形 class MyPrintCircle extends MyPoint{ @Override public void show() { for (int y = 0; y <2 * 5; y += 2) { int x = (int)Math.round(5 - Math.sqrt(2 * 5 * y - y * y)); int len = 2 * (5 - x); for (int i = 0; i <= x; i++) { System.out.print(' '); } System.out.print(''); for (int j = 0; j < len; j++) { System.out.prin(' '); System.out.println(''); } } } } public class MyPointTest { public static void Show(MyPoint a){ a.Show(); } public static void main(String[] args){ MyPoint mp1 = new MyPrintSquare(); MyPoint mp2 = new MyPrintCircle(); myShow(mp1); myShow(mp2); } }帮我修改为正确的代码
时间: 2024-03-16 15:44:06 浏览: 53
《打印不同的图形(Java)》实验报告
有几个地方需要修改:
1. `extend` 应该是 `extends`。
2. `Systemout` 应该是 `System.out`。
3. `Sytem.out.print` 应该是 `System.out.print`。
4. `Show` 应该是 `show`。
5. `myShow` 应该是 `Show`。
修改后的代码如下:
```
abstract class MyPoint {
public abstract void show();
}
// 打印正方形
class MyPrintSquare extends MyPoint {
@Override
public void show() {
for (int i = 0; i <= 5; ++i) {
for (int j = 1; j <= 5; ++j) {
if (j == 1 || j == 4)
System.out.print(' ');
if (i == 0 || i == 4)
System.out.print(' ');
else
System.out.print(' ');
}
System.out.println();
}
}
}
// 打印圆形
class MyPrintCircle extends MyPoint {
@Override
public void show() {
for (int y = 0; y < 2 * 5; y += 2) {
int x = (int) Math.round(5 - Math.sqrt(2 * 5 * y - y * y));
int len = 2 * (5 - x);
for (int i = 0; i <= x; i++) {
System.out.print(' ');
}
System.out.print('*');
for (int j = 0; j < len; j++) {
System.out.print(' ');
}
System.out.println('*');
}
for (int y = 2 * 5; y >= 0; y -= 2) {
int x = (int) Math.round(5 - Math.sqrt(2 * 5 * y - y * y));
int len = 2 * (5 - x);
for (int i = 0; i <= x; i++) {
System.out.print(' ');
}
System.out.print('*');
for (int j = 0; j < len; j++) {
System.out.print(' ');
}
System.out.println('*');
}
}
}
public class MyPointTest {
public static void show(MyPoint a) {
a.show();
}
public static void main(String[] args) {
MyPoint mp1 = new MyPrintSquare();
MyPoint mp2 = new MyPrintCircle();
show(mp1);
show(mp2);
}
}
```
阅读全文