刚开始学JAVA,我想输入长方形的长与宽,然后得出长方形的面积和周长,用application,请尽量写的简单一点,我想作为参考,谢谢

解决方案 »

  1.   

    不是作业啊,以下是我写的,大家帮我看看,是不是那里要改进的,或者你们可以写出一个更简单的
    import java.io.*;
    public class Changfangxing{
    public static void main(String[] args){
    float length,width;
    String s1,s2;
            BufferedReader bu1,bu2;
            try{
                System.out.print("请输入长方形的长:");
                bu1=new BufferedReader(new InputStreamReader(System.in));
                s1=bu1.readLine();
                System.out.println();
                System.out.print("请输入长方形的宽:");
                bu2=new BufferedReader(new InputStreamReader(System.in));
                s2=bu2.readLine();
                System.out.println();
      }
      catch(IOException e){
       System.out.println("不是数字型");
       return;
      }
    length=Float.parseFloat(s1);
    width=Float.parseFloat(s2);
    System.out.println("长方形的面积为:"+length*width);
    System.out.println("长方形的周长为:"+2*(length+width)); }
    }
      

  2.   

    bufferedreader 一个就够了,readline两次分别给长跟宽就可以了
    还有float通常精度有问题的,不如用double
      

  3.   

    简单版~
    import javax.swing.*;
    public class Fun{
         public static void main(String arg[]){
              int x=Integer.parseInt(JOption.showInputDialog("enter width:");
              int y=Interger.parseInt(JOpiont.showInputDialog("enter height:");
              JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
          }
    }要写异常,和其他的MM我
      

  4.   

    mport javax.swing.*;
    public class Fun{
    楼上:
    public static void main(String arg[]){
    int x=Integer.parseInt(JOption.showInputDialog("enter width:");//1
    int y=Interger.parseInt(JOpiont.showInputDialog("enter height:");//2
    JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);//3
    }
    错误:
    1.JOption->JOptionPane
    2.Interger->Integer,JOption->JOptionPane
    3.JOption->JOptionPane
      

  5.   

    好多错误,我改正后如下:import javax.swing.*;
    public class Fun{
         public static void main(String arg[]){
             double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:"));
             double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:"));
              JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
          }
    }
      

  6.   

    import javax.swing.*;
    public class Fun{
         public static void main(String arg[]){
             double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:"));
             double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:"));
              JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
          }
    }这个好,我一般都用JOptionPane.showInputDialog,不用BufferedReader,不知道哪个好点,另外LZ的代码不必写得那么复杂。