这个java程序要怎么改,怎么老是错误...
publicclassRectangle{privateintlength;privateintwindh;}publicclassRectangle(intlength...
public class Rectangle
{
private int length;
private int windh;
}
public class Rectangle(int length,int windth)
{
this.length=length;
this.windh=windh;
}
public void displayC()
{
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS()
{
int j =length*width;
System.out.println("面积是"+j);
}
public void display()
{
for(int i=1;i<=width;i++)
{
for(int j=1;j<=length;j++)
{
System.out.print("*");
}
}
System.out.println();
}
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,6);
r1.displayC();
r1.displayS();
r1.display();
} 展开
{
private int length;
private int windh;
}
public class Rectangle(int length,int windth)
{
this.length=length;
this.windh=windh;
}
public void displayC()
{
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS()
{
int j =length*width;
System.out.println("面积是"+j);
}
public void display()
{
for(int i=1;i<=width;i++)
{
for(int j=1;j<=length;j++)
{
System.out.print("*");
}
}
System.out.println();
}
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,6);
r1.displayC();
r1.displayS();
r1.display();
} 展开
3个回答
展开全部
public class Rectangle(int length,int windth)
这句话,中不能有 class,因为这是定义的构造方法,应该是
public Rectangle(int length,int windth)
{
this.length=length;
this.windh=windh;
}
这句话,中不能有 class,因为这是定义的构造方法,应该是
public Rectangle(int length,int windth)
{
this.length=length;
this.windh=windh;
}
追问
没有class错误非常多,你试一下 - -
追答
还有你的变量名前后写的不一致,括号位置也不对,我给你从头改了一下啊,你再看看:
public class Rectangle
{
private int length;
private int width;
public Rectangle(int length,int width)
{
this.length=length;
this.width=width;
}
public void displayC()
{
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS()
{
int j =length*width;
System.out.println("面积是"+j);
}
public void display()
{
for(int i=1;i<=width;i++)
{
for(int j=1;j<=length;j++)
{
System.out.print("*");
}
}
System.out.println();
}
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,6);
r1.displayC();
r1.displayS();
r1.display();
}
}
展开全部
public class Rectangle{
private int length;
private int width;
public void Rectangle(){
}
public void setValue(int length,int width){
this.length=length;
this.width=width;
}
public void displayC(){
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS(){
int j =length*width;
System.out.println("面积是"+j);
}
public void display(){
for(int i=1;i<=width;i++){
for(int j=1;j<=length;j++){
System.out.print("*");
}
}
System.out.println();
}
public static void main(String[] args){
Rectangle r1=new Rectangle();
r1.setValue(5,6);
r1.displayC();
r1.displayS();
r1.display();
}
}
private int length;
private int width;
public void Rectangle(){
}
public void setValue(int length,int width){
this.length=length;
this.width=width;
}
public void displayC(){
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS(){
int j =length*width;
System.out.println("面积是"+j);
}
public void display(){
for(int i=1;i<=width;i++){
for(int j=1;j<=length;j++){
System.out.print("*");
}
}
System.out.println();
}
public static void main(String[] args){
Rectangle r1=new Rectangle();
r1.setValue(5,6);
r1.displayC();
r1.displayS();
r1.display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
逐行比较确认错误——(原程序有很多设计不符合规范的地方,这里只是保证程序可以正确运行)
public class Rectangle{
private int length;
private int width;
public Rectangle(int length,int width)
{
this.length=length;
this.width=width;
}
public void displayC()
{
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS()
{
int j =length*width;
System.out.println("面积是"+j);
}
public void display()
{
for(int i=1;i<=width;i++)
{
for(int j=1;j<=length;j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,6);
r1.displayC();
r1.displayS();
r1.display();
}
}
public class Rectangle{
private int length;
private int width;
public Rectangle(int length,int width)
{
this.length=length;
this.width=width;
}
public void displayC()
{
int i =(length+width)*2;
System.out.println("周长是"+i);
}
public void displayS()
{
int j =length*width;
System.out.println("面积是"+j);
}
public void display()
{
for(int i=1;i<=width;i++)
{
for(int j=1;j<=length;j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,6);
r1.displayC();
r1.displayS();
r1.display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询