能帮忙看看哪里错了吗

做多做少不如做好 2019-10-22 07:23:12

import java.util.Scanner;

public class Test {
public static void main(String[] args) {
Circle circle=new Circle(1.5,1.6,2.0);
System.out.printf("圆的面积是::%.2f\n",circle.getArea());
do {
System.out.println("请输一个点:");
Scanner scn=new Scanner(System.in);
double x=scn.nextDouble();
double y=scn.nextDouble();
circle.contains(x,y);
System.out.println("是否继续?");
String command=scn.next();
}while(command.equalsIgnoreCase("y"));
}
}


public class Circle {
private double x;
private double y;
private double radius;

public Circle(double x,double y,double radius) {
this.x=x;
this.y=y;
this.radius=radius;
}

public double getArea(){
return Math.PI*radius*radius;
}
public void contains(double x,double y) {
if(radius*radius>Math.pow((x-this.x),2)+Math.pow((y-this.y), 2))
System.out.println("包含在内");
else
System.out.println("不包含在内");
}
}

...全文
69 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
莫莫绵 2019-10-22
  • 打赏
  • 举报
回复
String command
String command="";
do {
System.out.println("请输一个点:");
Scanner scn=new Scanner(System.in);
double x=scn.nextDouble();
double y=scn.nextDouble();
// circle.contains(x,y);
System.out.println("是否继续?");
command=scn.next();
}while(command.equalsIgnoreCase("y"));
; 在do while循环外面初始化一下
wowpH 2019-10-22
  • 打赏
  • 举报
回复
command是do-while里面的局部变量,在while括号里面不能用。

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧