笑傲心扬吧 关注:2贴子:91
  • 1回复贴,共1
6.1
class Rectangle
{
  private double width;
  private double height;
  static String color;
  public Rectangle()
  {
   double width=1;
   double height=1;
  }
  public Rectangle(double width,double height,String color)
  {
   this.width=width;
   this.height=height;
   this.color=color;
  }
  public double getWidth()
  {
   return width;
  }
  public void setWith(double width)
  {
   this.width=width;
  }
  public double getHeight()
  {
   return height;
  }
  public void setHeight(double height)
  {
   this.height=height;
  }
  public static String getColor()
  {
   return color;
  }
  public static void setColor(String newcolor)
  {
   color=newcolor;
  }
  public double findArea()
  {
   return width*height;
  }
  public double findPerimeter()
  {
   return 2*(width+height);
  }
}
 
 public class Test61
{
 public static void main(String[] args) 
 {
  Rectangle rect1=new Rectangle(4,40,"yellow");
  Rectangle rect2=new Rectangle(4,40,"yellow");
  System.out.println("Rectangle 1:\n"+"width: "+rect1.getWidth()+",height: "+rect1.getHeight()+",color: "+rect1.getColor()+",perimeter: "+rect1.findPerimeter()+",area: "+rect1.findArea());
  System.out.println("Rectangle 2:\n"+"width: "+rect2.getWidth()+",height: "+rect2.getHeight()+",color: "+rect2.getColor()+",perimeter: "+rect2.findPerimeter()+",area: "+rect2.findArea());
 }
}


IP属地:福建1楼2008-03-24 13:16回复
    7.3
    import javax.swing.JOptionPane;
    public class Test73
    {
    public static void main(String[] args) 
    {
    String first=JOptionPane.showInputDialog("Please input the first string");
     String second=JOptionPane.showInputDialog("Please input the second string");
    int result=second.indexOf(first);
    if(result==-1)
    JOptionPane.showMessageDialog(null,"NO! It is not a substring of the second!");
    else
    JOptionPane.showMessageDialog(null,"YES! It is a substring of the second!");
    }
    }


    IP属地:福建3楼2008-03-24 13:17
    回复